{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# pandas 进阶修炼 ｜早起Python\n",
    "<br>\n",
    "\n",
    "**本习题由公众号【早起Python & 可视化图鉴】 原创，转载及其他形式合作请与我们联系（微信号`sshs321`)，未经授权严禁搬运及二次创作，侵权必究！**\n",
    "\n",
    "\n",
    "\n",
    "本习题基于 `pandas` 版本 `1.1.3`，所有内容应当在 `Jupyter Notebook` 中执行以获得最佳效果。\n",
    "\n",
    "\n",
    "不同版本之间写法可能会有少许不同，如若碰到此情况，你应该学会如何自行检索解决。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7 - 数据透视与合并\n",
    "\n",
    "\n",
    "\n",
    "<br>\n",
    "\n",
    "**<font color = '#5172F0'><font size=3.5>必读👇👇👇**</font>\n",
    "    \n",
    "现在让我们继续练习 pandas数据分析另一组常用操作 --> **数据透视与合并**\n",
    "\n",
    "\n",
    "本节习题将涉及四大函数：\n",
    "    \n",
    "- pivot_table\n",
    "- concat\n",
    "- merge\n",
    "- join\n",
    "\n",
    "随着练习的深入，若没有一定的基础知识将很难继续刷题\n",
    "    \n",
    "官方文档永远是最好的学习手册，在本节之前强烈建议学习[官方文档对应部分](https://pandas.pydata.org/pandas-docs/version/0.20/merging.html#database-style-dataframe-joining-merging)\n",
    " \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 初始化\n",
    "\n",
    "<br>\n",
    "\n",
    "该 `Notebook` 版本为**纯习题版**\n",
    "\n",
    "如果需要答案或者提示，可以微信搜索公众号「早起Python」获取！"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据透视表\n",
    "\n",
    "![](http://liuzaoqi.oss-cn-beijing.aliyuncs.com/2021/09/14/16316101294678.jpg?域名/sample.jpg?x-oss-process=style/stylename)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1 - 加载数据\n",
    "\n",
    "读取当前目录下 `\"某超市销售数据.csv\"` 并设置千分位符号为 `,`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>邮寄方式</th>\n",
       "      <th>国家</th>\n",
       "      <th>地区</th>\n",
       "      <th>省/自治区</th>\n",
       "      <th>细分</th>\n",
       "      <th>类别</th>\n",
       "      <th>子类别</th>\n",
       "      <th>制造商</th>\n",
       "      <th>产品名称</th>\n",
       "      <th>数量</th>\n",
       "      <th>销售额</th>\n",
       "      <th>利润</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A1000001</td>\n",
       "      <td>2013/1/1</td>\n",
       "      <td>二级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>湖南</td>\n",
       "      <td>公司</td>\n",
       "      <td>办公用品</td>\n",
       "      <td>收纳具</td>\n",
       "      <td>Rogers</td>\n",
       "      <td>Rogers 文件车, 单宽度</td>\n",
       "      <td>5</td>\n",
       "      <td>3,305</td>\n",
       "      <td>1322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1000001</td>\n",
       "      <td>2013/1/1</td>\n",
       "      <td>二级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>湖南</td>\n",
       "      <td>公司</td>\n",
       "      <td>家具</td>\n",
       "      <td>桌子</td>\n",
       "      <td>Barricks</td>\n",
       "      <td>Barricks 圆桌, 白色</td>\n",
       "      <td>3</td>\n",
       "      <td>5,289</td>\n",
       "      <td>-635</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A1000001</td>\n",
       "      <td>2013/1/1</td>\n",
       "      <td>二级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>湖南</td>\n",
       "      <td>公司</td>\n",
       "      <td>技术</td>\n",
       "      <td>电话</td>\n",
       "      <td>诺基亚</td>\n",
       "      <td>诺基亚 智能手机, 整包</td>\n",
       "      <td>3</td>\n",
       "      <td>1,725</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A1000001</td>\n",
       "      <td>2013/1/1</td>\n",
       "      <td>二级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>湖南</td>\n",
       "      <td>公司</td>\n",
       "      <td>技术</td>\n",
       "      <td>配件</td>\n",
       "      <td>贝尔金</td>\n",
       "      <td>贝尔金 记忆卡, 实惠</td>\n",
       "      <td>3</td>\n",
       "      <td>1,607</td>\n",
       "      <td>611</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A1000003</td>\n",
       "      <td>2013/1/2</td>\n",
       "      <td>二级</td>\n",
       "      <td>中国</td>\n",
       "      <td>华东</td>\n",
       "      <td>福建</td>\n",
       "      <td>消费者</td>\n",
       "      <td>办公用品</td>\n",
       "      <td>收纳具</td>\n",
       "      <td>Rogers</td>\n",
       "      <td>Rogers 盒, 工业</td>\n",
       "      <td>4</td>\n",
       "      <td>456</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9930</th>\n",
       "      <td>A1004918</td>\n",
       "      <td>2016/12/30</td>\n",
       "      <td>标准级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>广东</td>\n",
       "      <td>消费者</td>\n",
       "      <td>技术</td>\n",
       "      <td>复印机</td>\n",
       "      <td>夏普</td>\n",
       "      <td>夏普 墨水, 红色</td>\n",
       "      <td>1</td>\n",
       "      <td>343</td>\n",
       "      <td>-172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9931</th>\n",
       "      <td>A1004918</td>\n",
       "      <td>2016/12/30</td>\n",
       "      <td>标准级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>广东</td>\n",
       "      <td>消费者</td>\n",
       "      <td>技术</td>\n",
       "      <td>电话</td>\n",
       "      <td>三星</td>\n",
       "      <td>三星 音频基座, 蓝色</td>\n",
       "      <td>2</td>\n",
       "      <td>934</td>\n",
       "      <td>-389</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9932</th>\n",
       "      <td>A1004924</td>\n",
       "      <td>2016/12/30</td>\n",
       "      <td>标准级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>广东</td>\n",
       "      <td>公司</td>\n",
       "      <td>技术</td>\n",
       "      <td>设备</td>\n",
       "      <td>松下</td>\n",
       "      <td>松下 收据打印机, 耐用</td>\n",
       "      <td>4</td>\n",
       "      <td>1,355</td>\n",
       "      <td>-113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9933</th>\n",
       "      <td>A1004924</td>\n",
       "      <td>2016/12/30</td>\n",
       "      <td>标准级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>广东</td>\n",
       "      <td>公司</td>\n",
       "      <td>技术</td>\n",
       "      <td>配件</td>\n",
       "      <td>Enermax</td>\n",
       "      <td>Enermax 键区, 回收</td>\n",
       "      <td>5</td>\n",
       "      <td>772</td>\n",
       "      <td>-181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9934</th>\n",
       "      <td>A1004919</td>\n",
       "      <td>2016/12/30</td>\n",
       "      <td>标准级</td>\n",
       "      <td>中国</td>\n",
       "      <td>中南</td>\n",
       "      <td>湖南</td>\n",
       "      <td>消费者</td>\n",
       "      <td>办公用品</td>\n",
       "      <td>信封</td>\n",
       "      <td>GlobeWeis</td>\n",
       "      <td>GlobeWeis 搭扣信封, 回收</td>\n",
       "      <td>3</td>\n",
       "      <td>122</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9935 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          订单ID        订单日期 邮寄方式  国家  地区 省/自治区   细分    类别  子类别        制造商  \\\n",
       "0     A1000001    2013/1/1   二级  中国  中南    湖南   公司  办公用品  收纳具     Rogers   \n",
       "1     A1000001    2013/1/1   二级  中国  中南    湖南   公司    家具   桌子   Barricks   \n",
       "2     A1000001    2013/1/1   二级  中国  中南    湖南   公司    技术   电话        诺基亚   \n",
       "3     A1000001    2013/1/1   二级  中国  中南    湖南   公司    技术   配件        贝尔金   \n",
       "4     A1000003    2013/1/2   二级  中国  华东    福建  消费者  办公用品  收纳具     Rogers   \n",
       "...        ...         ...  ...  ..  ..   ...  ...   ...  ...        ...   \n",
       "9930  A1004918  2016/12/30  标准级  中国  中南    广东  消费者    技术  复印机         夏普   \n",
       "9931  A1004918  2016/12/30  标准级  中国  中南    广东  消费者    技术   电话         三星   \n",
       "9932  A1004924  2016/12/30  标准级  中国  中南    广东   公司    技术   设备         松下   \n",
       "9933  A1004924  2016/12/30  标准级  中国  中南    广东   公司    技术   配件    Enermax   \n",
       "9934  A1004919  2016/12/30  标准级  中国  中南    湖南  消费者  办公用品   信封  GlobeWeis   \n",
       "\n",
       "                    产品名称  数量    销售额    利润  \n",
       "0        Rogers 文件车, 单宽度   5  3,305  1322  \n",
       "1        Barricks 圆桌, 白色   3  5,289  -635  \n",
       "2           诺基亚 智能手机, 整包   3  1,725    69  \n",
       "3            贝尔金 记忆卡, 实惠   3  1,607   611  \n",
       "4           Rogers 盒, 工业   4    456   128  \n",
       "...                  ...  ..    ...   ...  \n",
       "9930           夏普 墨水, 红色   1    343  -172  \n",
       "9931         三星 音频基座, 蓝色   2    934  -389  \n",
       "9932        松下 收据打印机, 耐用   4  1,355  -113  \n",
       "9933      Enermax 键区, 回收   5    772  -181  \n",
       "9934  GlobeWeis 搭扣信封, 回收   3    122    18  \n",
       "\n",
       "[9935 rows x 14 columns]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "df = pd.read_csv('./某超市销售数据.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['销售额'] = df.销售额.str.replace(',', '')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['销售额'] = df.销售额.astype(float)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2 - 数据透视｜默认\n",
    "\n",
    "制作各省「平均销售额」的数据透视表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>省/自治区</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>青海</th>\n",
       "      <td>2978.954545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江西</th>\n",
       "      <td>1966.477876</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陕西</th>\n",
       "      <td>1880.606635</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>上海</th>\n",
       "      <td>1875.712934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>云南</th>\n",
       "      <td>1863.789030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黑龙江</th>\n",
       "      <td>1800.438503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河北</th>\n",
       "      <td>1780.275248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山西</th>\n",
       "      <td>1751.359184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>福建</th>\n",
       "      <td>1732.044693</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>北京</th>\n",
       "      <td>1726.857143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>海南</th>\n",
       "      <td>1721.982759</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>吉林</th>\n",
       "      <td>1701.563567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广西</th>\n",
       "      <td>1675.061135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>宁夏</th>\n",
       "      <td>1651.680000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山东</th>\n",
       "      <td>1642.659111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>天津</th>\n",
       "      <td>1611.206667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖南</th>\n",
       "      <td>1603.702222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>甘肃</th>\n",
       "      <td>1602.893443</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广东</th>\n",
       "      <td>1592.185340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河南</th>\n",
       "      <td>1558.400335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>安徽</th>\n",
       "      <td>1477.868251</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>贵州</th>\n",
       "      <td>1425.978723</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新疆</th>\n",
       "      <td>1402.384615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>重庆</th>\n",
       "      <td>1383.082927</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>辽宁</th>\n",
       "      <td>1363.381982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>浙江</th>\n",
       "      <td>1347.277778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖北</th>\n",
       "      <td>1324.808442</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>内蒙古</th>\n",
       "      <td>1314.826316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江苏</th>\n",
       "      <td>1279.898089</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>四川</th>\n",
       "      <td>1157.875536</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>西藏</th>\n",
       "      <td>201.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               销售额\n",
       "省/自治区             \n",
       "青海     2978.954545\n",
       "江西     1966.477876\n",
       "陕西     1880.606635\n",
       "上海     1875.712934\n",
       "云南     1863.789030\n",
       "黑龙江    1800.438503\n",
       "河北     1780.275248\n",
       "山西     1751.359184\n",
       "福建     1732.044693\n",
       "北京     1726.857143\n",
       "海南     1721.982759\n",
       "吉林     1701.563567\n",
       "广西     1675.061135\n",
       "宁夏     1651.680000\n",
       "山东     1642.659111\n",
       "天津     1611.206667\n",
       "湖南     1603.702222\n",
       "甘肃     1602.893443\n",
       "广东     1592.185340\n",
       "河南     1558.400335\n",
       "安徽     1477.868251\n",
       "贵州     1425.978723\n",
       "新疆     1402.384615\n",
       "重庆     1383.082927\n",
       "辽宁     1363.381982\n",
       "浙江     1347.277778\n",
       "湖北     1324.808442\n",
       "内蒙古    1314.826316\n",
       "江苏     1279.898089\n",
       "四川     1157.875536\n",
       "西藏      201.000000"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.pivot_table(df, index='省/自治区',  values=['销售额'], aggfunc=np.mean).sort_values('销售额', ascending=False)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3 - 数据透视｜指定方法\n",
    "\n",
    "制作各省「销售总额」的数据透视表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>省/自治区</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>上海</th>\n",
       "      <td>594601.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>云南</th>\n",
       "      <td>441718.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>内蒙古</th>\n",
       "      <td>249817.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>北京</th>\n",
       "      <td>350552.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>吉林</th>\n",
       "      <td>896724.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>四川</th>\n",
       "      <td>269785.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>天津</th>\n",
       "      <td>483362.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>宁夏</th>\n",
       "      <td>41292.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>安徽</th>\n",
       "      <td>684253.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山东</th>\n",
       "      <td>1884130.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山西</th>\n",
       "      <td>429083.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广东</th>\n",
       "      <td>1520537.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广西</th>\n",
       "      <td>383589.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新疆</th>\n",
       "      <td>72924.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江苏</th>\n",
       "      <td>401888.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江西</th>\n",
       "      <td>222212.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河北</th>\n",
       "      <td>899039.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河南</th>\n",
       "      <td>930365.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>浙江</th>\n",
       "      <td>266761.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>海南</th>\n",
       "      <td>99875.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖北</th>\n",
       "      <td>408041.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖南</th>\n",
       "      <td>721666.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>甘肃</th>\n",
       "      <td>195553.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>福建</th>\n",
       "      <td>620072.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>西藏</th>\n",
       "      <td>201.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>贵州</th>\n",
       "      <td>67021.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>辽宁</th>\n",
       "      <td>756677.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>重庆</th>\n",
       "      <td>283532.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陕西</th>\n",
       "      <td>396808.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>青海</th>\n",
       "      <td>65537.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黑龙江</th>\n",
       "      <td>1346728.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             销售额\n",
       "省/自治区           \n",
       "上海      594601.0\n",
       "云南      441718.0\n",
       "内蒙古     249817.0\n",
       "北京      350552.0\n",
       "吉林      896724.0\n",
       "四川      269785.0\n",
       "天津      483362.0\n",
       "宁夏       41292.0\n",
       "安徽      684253.0\n",
       "山东     1884130.0\n",
       "山西      429083.0\n",
       "广东     1520537.0\n",
       "广西      383589.0\n",
       "新疆       72924.0\n",
       "江苏      401888.0\n",
       "江西      222212.0\n",
       "河北      899039.0\n",
       "河南      930365.0\n",
       "浙江      266761.0\n",
       "海南       99875.0\n",
       "湖北      408041.0\n",
       "湖南      721666.0\n",
       "甘肃      195553.0\n",
       "福建      620072.0\n",
       "西藏         201.0\n",
       "贵州       67021.0\n",
       "辽宁      756677.0\n",
       "重庆      283532.0\n",
       "陕西      396808.0\n",
       "青海       65537.0\n",
       "黑龙江    1346728.0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pivot_table(index='省/自治区', values='销售额', aggfunc=np.sum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4 - 数据透视｜多方法\n",
    "\n",
    "制作各省「销售总额」与「平均销售额」的数据透视表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>sum</th>\n",
       "      <th>mean</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>销售额</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>省/自治区</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>上海</th>\n",
       "      <td>594601.0</td>\n",
       "      <td>1875.712934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>云南</th>\n",
       "      <td>441718.0</td>\n",
       "      <td>1863.789030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>内蒙古</th>\n",
       "      <td>249817.0</td>\n",
       "      <td>1314.826316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>北京</th>\n",
       "      <td>350552.0</td>\n",
       "      <td>1726.857143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>吉林</th>\n",
       "      <td>896724.0</td>\n",
       "      <td>1701.563567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>四川</th>\n",
       "      <td>269785.0</td>\n",
       "      <td>1157.875536</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>天津</th>\n",
       "      <td>483362.0</td>\n",
       "      <td>1611.206667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>宁夏</th>\n",
       "      <td>41292.0</td>\n",
       "      <td>1651.680000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>安徽</th>\n",
       "      <td>684253.0</td>\n",
       "      <td>1477.868251</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山东</th>\n",
       "      <td>1884130.0</td>\n",
       "      <td>1642.659111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山西</th>\n",
       "      <td>429083.0</td>\n",
       "      <td>1751.359184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广东</th>\n",
       "      <td>1520537.0</td>\n",
       "      <td>1592.185340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广西</th>\n",
       "      <td>383589.0</td>\n",
       "      <td>1675.061135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新疆</th>\n",
       "      <td>72924.0</td>\n",
       "      <td>1402.384615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江苏</th>\n",
       "      <td>401888.0</td>\n",
       "      <td>1279.898089</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江西</th>\n",
       "      <td>222212.0</td>\n",
       "      <td>1966.477876</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河北</th>\n",
       "      <td>899039.0</td>\n",
       "      <td>1780.275248</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河南</th>\n",
       "      <td>930365.0</td>\n",
       "      <td>1558.400335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>浙江</th>\n",
       "      <td>266761.0</td>\n",
       "      <td>1347.277778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>海南</th>\n",
       "      <td>99875.0</td>\n",
       "      <td>1721.982759</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖北</th>\n",
       "      <td>408041.0</td>\n",
       "      <td>1324.808442</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖南</th>\n",
       "      <td>721666.0</td>\n",
       "      <td>1603.702222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>甘肃</th>\n",
       "      <td>195553.0</td>\n",
       "      <td>1602.893443</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>福建</th>\n",
       "      <td>620072.0</td>\n",
       "      <td>1732.044693</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>西藏</th>\n",
       "      <td>201.0</td>\n",
       "      <td>201.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>贵州</th>\n",
       "      <td>67021.0</td>\n",
       "      <td>1425.978723</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>辽宁</th>\n",
       "      <td>756677.0</td>\n",
       "      <td>1363.381982</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>重庆</th>\n",
       "      <td>283532.0</td>\n",
       "      <td>1383.082927</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陕西</th>\n",
       "      <td>396808.0</td>\n",
       "      <td>1880.606635</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>青海</th>\n",
       "      <td>65537.0</td>\n",
       "      <td>2978.954545</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黑龙江</th>\n",
       "      <td>1346728.0</td>\n",
       "      <td>1800.438503</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             sum         mean\n",
       "             销售额          销售额\n",
       "省/自治区                        \n",
       "上海      594601.0  1875.712934\n",
       "云南      441718.0  1863.789030\n",
       "内蒙古     249817.0  1314.826316\n",
       "北京      350552.0  1726.857143\n",
       "吉林      896724.0  1701.563567\n",
       "四川      269785.0  1157.875536\n",
       "天津      483362.0  1611.206667\n",
       "宁夏       41292.0  1651.680000\n",
       "安徽      684253.0  1477.868251\n",
       "山东     1884130.0  1642.659111\n",
       "山西      429083.0  1751.359184\n",
       "广东     1520537.0  1592.185340\n",
       "广西      383589.0  1675.061135\n",
       "新疆       72924.0  1402.384615\n",
       "江苏      401888.0  1279.898089\n",
       "江西      222212.0  1966.477876\n",
       "河北      899039.0  1780.275248\n",
       "河南      930365.0  1558.400335\n",
       "浙江      266761.0  1347.277778\n",
       "海南       99875.0  1721.982759\n",
       "湖北      408041.0  1324.808442\n",
       "湖南      721666.0  1603.702222\n",
       "甘肃      195553.0  1602.893443\n",
       "福建      620072.0  1732.044693\n",
       "西藏         201.0   201.000000\n",
       "贵州       67021.0  1425.978723\n",
       "辽宁      756677.0  1363.381982\n",
       "重庆      283532.0  1383.082927\n",
       "陕西      396808.0  1880.606635\n",
       "青海       65537.0  2978.954545\n",
       "黑龙江    1346728.0  1800.438503"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pivot_table(index='省/自治区', values='销售额', aggfunc=[np.sum, np.mean])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5 - 数据透视｜多指标\n",
    "\n",
    "制作各省市「销售总额」与「利润总额」的数据透视表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">sum</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>利润</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>省/自治区</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>上海</th>\n",
       "      <td>87236</td>\n",
       "      <td>594601.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>云南</th>\n",
       "      <td>83201</td>\n",
       "      <td>441718.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>内蒙古</th>\n",
       "      <td>-20685</td>\n",
       "      <td>249817.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>北京</th>\n",
       "      <td>57883</td>\n",
       "      <td>350552.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>吉林</th>\n",
       "      <td>152504</td>\n",
       "      <td>896724.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>四川</th>\n",
       "      <td>-16615</td>\n",
       "      <td>269785.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>天津</th>\n",
       "      <td>63108</td>\n",
       "      <td>483362.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>宁夏</th>\n",
       "      <td>-1149</td>\n",
       "      <td>41292.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>安徽</th>\n",
       "      <td>133312</td>\n",
       "      <td>684253.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山东</th>\n",
       "      <td>310042</td>\n",
       "      <td>1884130.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>山西</th>\n",
       "      <td>79913</td>\n",
       "      <td>429083.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广东</th>\n",
       "      <td>278591</td>\n",
       "      <td>1520537.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>广西</th>\n",
       "      <td>61444</td>\n",
       "      <td>383589.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>新疆</th>\n",
       "      <td>13696</td>\n",
       "      <td>72924.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江苏</th>\n",
       "      <td>-6500</td>\n",
       "      <td>401888.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>江西</th>\n",
       "      <td>27144</td>\n",
       "      <td>222212.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河北</th>\n",
       "      <td>153247</td>\n",
       "      <td>899039.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>河南</th>\n",
       "      <td>168714</td>\n",
       "      <td>930365.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>浙江</th>\n",
       "      <td>-17024</td>\n",
       "      <td>266761.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>海南</th>\n",
       "      <td>21298</td>\n",
       "      <td>99875.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖北</th>\n",
       "      <td>-22896</td>\n",
       "      <td>408041.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>湖南</th>\n",
       "      <td>92944</td>\n",
       "      <td>721666.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>甘肃</th>\n",
       "      <td>-25298</td>\n",
       "      <td>195553.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>福建</th>\n",
       "      <td>133791</td>\n",
       "      <td>620072.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>西藏</th>\n",
       "      <td>4</td>\n",
       "      <td>201.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>贵州</th>\n",
       "      <td>5408</td>\n",
       "      <td>67021.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>辽宁</th>\n",
       "      <td>-24930</td>\n",
       "      <td>756677.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>重庆</th>\n",
       "      <td>39688</td>\n",
       "      <td>283532.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>陕西</th>\n",
       "      <td>61753</td>\n",
       "      <td>396808.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>青海</th>\n",
       "      <td>4354</td>\n",
       "      <td>65537.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黑龙江</th>\n",
       "      <td>228262</td>\n",
       "      <td>1346728.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          sum           \n",
       "           利润        销售额\n",
       "省/自治区                   \n",
       "上海      87236   594601.0\n",
       "云南      83201   441718.0\n",
       "内蒙古    -20685   249817.0\n",
       "北京      57883   350552.0\n",
       "吉林     152504   896724.0\n",
       "四川     -16615   269785.0\n",
       "天津      63108   483362.0\n",
       "宁夏      -1149    41292.0\n",
       "安徽     133312   684253.0\n",
       "山东     310042  1884130.0\n",
       "山西      79913   429083.0\n",
       "广东     278591  1520537.0\n",
       "广西      61444   383589.0\n",
       "新疆      13696    72924.0\n",
       "江苏      -6500   401888.0\n",
       "江西      27144   222212.0\n",
       "河北     153247   899039.0\n",
       "河南     168714   930365.0\n",
       "浙江     -17024   266761.0\n",
       "海南      21298    99875.0\n",
       "湖北     -22896   408041.0\n",
       "湖南      92944   721666.0\n",
       "甘肃     -25298   195553.0\n",
       "福建     133791   620072.0\n",
       "西藏          4      201.0\n",
       "贵州       5408    67021.0\n",
       "辽宁     -24930   756677.0\n",
       "重庆      39688   283532.0\n",
       "陕西      61753   396808.0\n",
       "青海       4354    65537.0\n",
       "黑龙江    228262  1346728.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pivot_table(index='省/自治区', values=['销售额', '利润'], aggfunc=[np.sum])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6 - 数据透视｜多索引\n",
    "\n",
    "制作「各省市」与「不同类别」产品「销售总额」的数据透视表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_8ff81_row28_col0 {\n",
       "  background-color: yellow;\n",
       "}\n",
       "#T_8ff81_row72_col0 {\n",
       "  background-color: #008800;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_8ff81_\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank\" >&nbsp;</th>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th class=\"col_heading level0 col0\" >销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th class=\"index_name level0\" >省/自治区</th>\n",
       "      <th class=\"index_name level1\" >类别</th>\n",
       "      <th class=\"blank col0\" >&nbsp;</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row0\" class=\"row_heading level0 row0\" rowspan=\"3\">上海</th>\n",
       "      <th id=\"T_8ff81_level1_row0\" class=\"row_heading level1 row0\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row0_col0\" class=\"data row0 col0\" >198529.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row1\" class=\"row_heading level1 row1\" >家具</th>\n",
       "      <td id=\"T_8ff81_row1_col0\" class=\"data row1 col0\" >221058.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row2\" class=\"row_heading level1 row2\" >技术</th>\n",
       "      <td id=\"T_8ff81_row2_col0\" class=\"data row2 col0\" >175014.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row3\" class=\"row_heading level0 row3\" rowspan=\"3\">云南</th>\n",
       "      <th id=\"T_8ff81_level1_row3\" class=\"row_heading level1 row3\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row3_col0\" class=\"data row3 col0\" >123051.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row4\" class=\"row_heading level1 row4\" >家具</th>\n",
       "      <td id=\"T_8ff81_row4_col0\" class=\"data row4 col0\" >174155.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row5\" class=\"row_heading level1 row5\" >技术</th>\n",
       "      <td id=\"T_8ff81_row5_col0\" class=\"data row5 col0\" >144512.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row6\" class=\"row_heading level0 row6\" rowspan=\"3\">内蒙古</th>\n",
       "      <th id=\"T_8ff81_level1_row6\" class=\"row_heading level1 row6\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row6_col0\" class=\"data row6 col0\" >74058.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row7\" class=\"row_heading level1 row7\" >家具</th>\n",
       "      <td id=\"T_8ff81_row7_col0\" class=\"data row7 col0\" >95426.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row8\" class=\"row_heading level1 row8\" >技术</th>\n",
       "      <td id=\"T_8ff81_row8_col0\" class=\"data row8 col0\" >80333.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row9\" class=\"row_heading level0 row9\" rowspan=\"3\">北京</th>\n",
       "      <th id=\"T_8ff81_level1_row9\" class=\"row_heading level1 row9\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row9_col0\" class=\"data row9 col0\" >144232.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row10\" class=\"row_heading level1 row10\" >家具</th>\n",
       "      <td id=\"T_8ff81_row10_col0\" class=\"data row10 col0\" >127407.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row11\" class=\"row_heading level1 row11\" >技术</th>\n",
       "      <td id=\"T_8ff81_row11_col0\" class=\"data row11 col0\" >78913.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row12\" class=\"row_heading level0 row12\" rowspan=\"3\">吉林</th>\n",
       "      <th id=\"T_8ff81_level1_row12\" class=\"row_heading level1 row12\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row12_col0\" class=\"data row12 col0\" >215143.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row13\" class=\"row_heading level1 row13\" >家具</th>\n",
       "      <td id=\"T_8ff81_row13_col0\" class=\"data row13 col0\" >287498.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row14\" class=\"row_heading level1 row14\" >技术</th>\n",
       "      <td id=\"T_8ff81_row14_col0\" class=\"data row14 col0\" >394083.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row15\" class=\"row_heading level0 row15\" rowspan=\"3\">四川</th>\n",
       "      <th id=\"T_8ff81_level1_row15\" class=\"row_heading level1 row15\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row15_col0\" class=\"data row15 col0\" >111393.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row16\" class=\"row_heading level1 row16\" >家具</th>\n",
       "      <td id=\"T_8ff81_row16_col0\" class=\"data row16 col0\" >88297.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row17\" class=\"row_heading level1 row17\" >技术</th>\n",
       "      <td id=\"T_8ff81_row17_col0\" class=\"data row17 col0\" >70095.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row18\" class=\"row_heading level0 row18\" rowspan=\"3\">天津</th>\n",
       "      <th id=\"T_8ff81_level1_row18\" class=\"row_heading level1 row18\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row18_col0\" class=\"data row18 col0\" >142526.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row19\" class=\"row_heading level1 row19\" >家具</th>\n",
       "      <td id=\"T_8ff81_row19_col0\" class=\"data row19 col0\" >149452.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row20\" class=\"row_heading level1 row20\" >技术</th>\n",
       "      <td id=\"T_8ff81_row20_col0\" class=\"data row20 col0\" >191384.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row21\" class=\"row_heading level0 row21\" rowspan=\"3\">宁夏</th>\n",
       "      <th id=\"T_8ff81_level1_row21\" class=\"row_heading level1 row21\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row21_col0\" class=\"data row21 col0\" >19529.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row22\" class=\"row_heading level1 row22\" >家具</th>\n",
       "      <td id=\"T_8ff81_row22_col0\" class=\"data row22 col0\" >16449.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row23\" class=\"row_heading level1 row23\" >技术</th>\n",
       "      <td id=\"T_8ff81_row23_col0\" class=\"data row23 col0\" >5314.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row24\" class=\"row_heading level0 row24\" rowspan=\"3\">安徽</th>\n",
       "      <th id=\"T_8ff81_level1_row24\" class=\"row_heading level1 row24\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row24_col0\" class=\"data row24 col0\" >200511.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row25\" class=\"row_heading level1 row25\" >家具</th>\n",
       "      <td id=\"T_8ff81_row25_col0\" class=\"data row25 col0\" >215901.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row26\" class=\"row_heading level1 row26\" >技术</th>\n",
       "      <td id=\"T_8ff81_row26_col0\" class=\"data row26 col0\" >267841.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row27\" class=\"row_heading level0 row27\" rowspan=\"3\">山东</th>\n",
       "      <th id=\"T_8ff81_level1_row27\" class=\"row_heading level1 row27\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row27_col0\" class=\"data row27 col0\" >575520.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row28\" class=\"row_heading level1 row28\" >家具</th>\n",
       "      <td id=\"T_8ff81_row28_col0\" class=\"data row28 col0\" >664339.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row29\" class=\"row_heading level1 row29\" >技术</th>\n",
       "      <td id=\"T_8ff81_row29_col0\" class=\"data row29 col0\" >644271.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row30\" class=\"row_heading level0 row30\" rowspan=\"3\">山西</th>\n",
       "      <th id=\"T_8ff81_level1_row30\" class=\"row_heading level1 row30\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row30_col0\" class=\"data row30 col0\" >121458.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row31\" class=\"row_heading level1 row31\" >家具</th>\n",
       "      <td id=\"T_8ff81_row31_col0\" class=\"data row31 col0\" >175522.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row32\" class=\"row_heading level1 row32\" >技术</th>\n",
       "      <td id=\"T_8ff81_row32_col0\" class=\"data row32 col0\" >132103.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row33\" class=\"row_heading level0 row33\" rowspan=\"3\">广东</th>\n",
       "      <th id=\"T_8ff81_level1_row33\" class=\"row_heading level1 row33\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row33_col0\" class=\"data row33 col0\" >494643.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row34\" class=\"row_heading level1 row34\" >家具</th>\n",
       "      <td id=\"T_8ff81_row34_col0\" class=\"data row34 col0\" >530054.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row35\" class=\"row_heading level1 row35\" >技术</th>\n",
       "      <td id=\"T_8ff81_row35_col0\" class=\"data row35 col0\" >495840.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row36\" class=\"row_heading level0 row36\" rowspan=\"3\">广西</th>\n",
       "      <th id=\"T_8ff81_level1_row36\" class=\"row_heading level1 row36\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row36_col0\" class=\"data row36 col0\" >102625.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row37\" class=\"row_heading level1 row37\" >家具</th>\n",
       "      <td id=\"T_8ff81_row37_col0\" class=\"data row37 col0\" >165140.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row38\" class=\"row_heading level1 row38\" >技术</th>\n",
       "      <td id=\"T_8ff81_row38_col0\" class=\"data row38 col0\" >115824.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row39\" class=\"row_heading level0 row39\" rowspan=\"3\">新疆</th>\n",
       "      <th id=\"T_8ff81_level1_row39\" class=\"row_heading level1 row39\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row39_col0\" class=\"data row39 col0\" >38345.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row40\" class=\"row_heading level1 row40\" >家具</th>\n",
       "      <td id=\"T_8ff81_row40_col0\" class=\"data row40 col0\" >20520.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row41\" class=\"row_heading level1 row41\" >技术</th>\n",
       "      <td id=\"T_8ff81_row41_col0\" class=\"data row41 col0\" >14059.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row42\" class=\"row_heading level0 row42\" rowspan=\"3\">江苏</th>\n",
       "      <th id=\"T_8ff81_level1_row42\" class=\"row_heading level1 row42\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row42_col0\" class=\"data row42 col0\" >163919.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row43\" class=\"row_heading level1 row43\" >家具</th>\n",
       "      <td id=\"T_8ff81_row43_col0\" class=\"data row43 col0\" >152868.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row44\" class=\"row_heading level1 row44\" >技术</th>\n",
       "      <td id=\"T_8ff81_row44_col0\" class=\"data row44 col0\" >85101.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row45\" class=\"row_heading level0 row45\" rowspan=\"3\">江西</th>\n",
       "      <th id=\"T_8ff81_level1_row45\" class=\"row_heading level1 row45\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row45_col0\" class=\"data row45 col0\" >37114.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row46\" class=\"row_heading level1 row46\" >家具</th>\n",
       "      <td id=\"T_8ff81_row46_col0\" class=\"data row46 col0\" >107047.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row47\" class=\"row_heading level1 row47\" >技术</th>\n",
       "      <td id=\"T_8ff81_row47_col0\" class=\"data row47 col0\" >78051.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row48\" class=\"row_heading level0 row48\" rowspan=\"3\">河北</th>\n",
       "      <th id=\"T_8ff81_level1_row48\" class=\"row_heading level1 row48\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row48_col0\" class=\"data row48 col0\" >284739.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row49\" class=\"row_heading level1 row49\" >家具</th>\n",
       "      <td id=\"T_8ff81_row49_col0\" class=\"data row49 col0\" >306535.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row50\" class=\"row_heading level1 row50\" >技术</th>\n",
       "      <td id=\"T_8ff81_row50_col0\" class=\"data row50 col0\" >307765.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row51\" class=\"row_heading level0 row51\" rowspan=\"3\">河南</th>\n",
       "      <th id=\"T_8ff81_level1_row51\" class=\"row_heading level1 row51\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row51_col0\" class=\"data row51 col0\" >266916.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row52\" class=\"row_heading level1 row52\" >家具</th>\n",
       "      <td id=\"T_8ff81_row52_col0\" class=\"data row52 col0\" >294593.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row53\" class=\"row_heading level1 row53\" >技术</th>\n",
       "      <td id=\"T_8ff81_row53_col0\" class=\"data row53 col0\" >368856.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row54\" class=\"row_heading level0 row54\" rowspan=\"3\">浙江</th>\n",
       "      <th id=\"T_8ff81_level1_row54\" class=\"row_heading level1 row54\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row54_col0\" class=\"data row54 col0\" >84471.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row55\" class=\"row_heading level1 row55\" >家具</th>\n",
       "      <td id=\"T_8ff81_row55_col0\" class=\"data row55 col0\" >84436.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row56\" class=\"row_heading level1 row56\" >技术</th>\n",
       "      <td id=\"T_8ff81_row56_col0\" class=\"data row56 col0\" >97854.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row57\" class=\"row_heading level0 row57\" rowspan=\"3\">海南</th>\n",
       "      <th id=\"T_8ff81_level1_row57\" class=\"row_heading level1 row57\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row57_col0\" class=\"data row57 col0\" >34141.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row58\" class=\"row_heading level1 row58\" >家具</th>\n",
       "      <td id=\"T_8ff81_row58_col0\" class=\"data row58 col0\" >41225.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row59\" class=\"row_heading level1 row59\" >技术</th>\n",
       "      <td id=\"T_8ff81_row59_col0\" class=\"data row59 col0\" >24509.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row60\" class=\"row_heading level0 row60\" rowspan=\"3\">湖北</th>\n",
       "      <th id=\"T_8ff81_level1_row60\" class=\"row_heading level1 row60\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row60_col0\" class=\"data row60 col0\" >112230.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row61\" class=\"row_heading level1 row61\" >家具</th>\n",
       "      <td id=\"T_8ff81_row61_col0\" class=\"data row61 col0\" >118053.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row62\" class=\"row_heading level1 row62\" >技术</th>\n",
       "      <td id=\"T_8ff81_row62_col0\" class=\"data row62 col0\" >177758.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row63\" class=\"row_heading level0 row63\" rowspan=\"3\">湖南</th>\n",
       "      <th id=\"T_8ff81_level1_row63\" class=\"row_heading level1 row63\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row63_col0\" class=\"data row63 col0\" >197969.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row64\" class=\"row_heading level1 row64\" >家具</th>\n",
       "      <td id=\"T_8ff81_row64_col0\" class=\"data row64 col0\" >241804.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row65\" class=\"row_heading level1 row65\" >技术</th>\n",
       "      <td id=\"T_8ff81_row65_col0\" class=\"data row65 col0\" >281893.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row66\" class=\"row_heading level0 row66\" rowspan=\"3\">甘肃</th>\n",
       "      <th id=\"T_8ff81_level1_row66\" class=\"row_heading level1 row66\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row66_col0\" class=\"data row66 col0\" >54012.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row67\" class=\"row_heading level1 row67\" >家具</th>\n",
       "      <td id=\"T_8ff81_row67_col0\" class=\"data row67 col0\" >68657.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row68\" class=\"row_heading level1 row68\" >技术</th>\n",
       "      <td id=\"T_8ff81_row68_col0\" class=\"data row68 col0\" >72884.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row69\" class=\"row_heading level0 row69\" rowspan=\"3\">福建</th>\n",
       "      <th id=\"T_8ff81_level1_row69\" class=\"row_heading level1 row69\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row69_col0\" class=\"data row69 col0\" >142728.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row70\" class=\"row_heading level1 row70\" >家具</th>\n",
       "      <td id=\"T_8ff81_row70_col0\" class=\"data row70 col0\" >243289.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row71\" class=\"row_heading level1 row71\" >技术</th>\n",
       "      <td id=\"T_8ff81_row71_col0\" class=\"data row71 col0\" >234055.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row72\" class=\"row_heading level0 row72\" >西藏</th>\n",
       "      <th id=\"T_8ff81_level1_row72\" class=\"row_heading level1 row72\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row72_col0\" class=\"data row72 col0\" >201.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row73\" class=\"row_heading level0 row73\" rowspan=\"3\">贵州</th>\n",
       "      <th id=\"T_8ff81_level1_row73\" class=\"row_heading level1 row73\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row73_col0\" class=\"data row73 col0\" >9713.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row74\" class=\"row_heading level1 row74\" >家具</th>\n",
       "      <td id=\"T_8ff81_row74_col0\" class=\"data row74 col0\" >29285.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row75\" class=\"row_heading level1 row75\" >技术</th>\n",
       "      <td id=\"T_8ff81_row75_col0\" class=\"data row75 col0\" >28023.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row76\" class=\"row_heading level0 row76\" rowspan=\"3\">辽宁</th>\n",
       "      <th id=\"T_8ff81_level1_row76\" class=\"row_heading level1 row76\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row76_col0\" class=\"data row76 col0\" >214994.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row77\" class=\"row_heading level1 row77\" >家具</th>\n",
       "      <td id=\"T_8ff81_row77_col0\" class=\"data row77 col0\" >270279.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row78\" class=\"row_heading level1 row78\" >技术</th>\n",
       "      <td id=\"T_8ff81_row78_col0\" class=\"data row78 col0\" >271404.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row79\" class=\"row_heading level0 row79\" rowspan=\"3\">重庆</th>\n",
       "      <th id=\"T_8ff81_level1_row79\" class=\"row_heading level1 row79\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row79_col0\" class=\"data row79 col0\" >71020.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row80\" class=\"row_heading level1 row80\" >家具</th>\n",
       "      <td id=\"T_8ff81_row80_col0\" class=\"data row80 col0\" >96318.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row81\" class=\"row_heading level1 row81\" >技术</th>\n",
       "      <td id=\"T_8ff81_row81_col0\" class=\"data row81 col0\" >116194.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row82\" class=\"row_heading level0 row82\" rowspan=\"3\">陕西</th>\n",
       "      <th id=\"T_8ff81_level1_row82\" class=\"row_heading level1 row82\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row82_col0\" class=\"data row82 col0\" >119169.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row83\" class=\"row_heading level1 row83\" >家具</th>\n",
       "      <td id=\"T_8ff81_row83_col0\" class=\"data row83 col0\" >187497.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row84\" class=\"row_heading level1 row84\" >技术</th>\n",
       "      <td id=\"T_8ff81_row84_col0\" class=\"data row84 col0\" >90142.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row85\" class=\"row_heading level0 row85\" rowspan=\"3\">青海</th>\n",
       "      <th id=\"T_8ff81_level1_row85\" class=\"row_heading level1 row85\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row85_col0\" class=\"data row85 col0\" >16718.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row86\" class=\"row_heading level1 row86\" >家具</th>\n",
       "      <td id=\"T_8ff81_row86_col0\" class=\"data row86 col0\" >25923.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row87\" class=\"row_heading level1 row87\" >技术</th>\n",
       "      <td id=\"T_8ff81_row87_col0\" class=\"data row87 col0\" >22896.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level0_row88\" class=\"row_heading level0 row88\" rowspan=\"3\">黑龙江</th>\n",
       "      <th id=\"T_8ff81_level1_row88\" class=\"row_heading level1 row88\" >办公用品</th>\n",
       "      <td id=\"T_8ff81_row88_col0\" class=\"data row88 col0\" >473319.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row89\" class=\"row_heading level1 row89\" >家具</th>\n",
       "      <td id=\"T_8ff81_row89_col0\" class=\"data row89 col0\" >497504.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_8ff81_level1_row90\" class=\"row_heading level1 row90\" >技术</th>\n",
       "      <td id=\"T_8ff81_row90_col0\" class=\"data row90 col0\" >375905.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x16bb875aac0>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(df.pivot_table(index=['省/自治区', '类别'], values='销售额',aggfunc=np.sum).style\n",
    "    .highlight_max()\n",
    "    .highlight_min(color=\"#008800\")\n",
    "    .highlight_null()\n",
    ")\n",
    "#df.dtypes\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_2f85e_row28_col0 {\n",
       "  background-color: yellow;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_2f85e_\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank\" >&nbsp;</th>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th class=\"col_heading level0 col0\" >销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th class=\"index_name level0\" >省/自治区</th>\n",
       "      <th class=\"index_name level1\" >类别</th>\n",
       "      <th class=\"blank col0\" >&nbsp;</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row0\" class=\"row_heading level0 row0\" rowspan=\"3\">上海</th>\n",
       "      <th id=\"T_2f85e_level1_row0\" class=\"row_heading level1 row0\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row0_col0\" class=\"data row0 col0\" >198529.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row1\" class=\"row_heading level1 row1\" >家具</th>\n",
       "      <td id=\"T_2f85e_row1_col0\" class=\"data row1 col0\" >221058.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row2\" class=\"row_heading level1 row2\" >技术</th>\n",
       "      <td id=\"T_2f85e_row2_col0\" class=\"data row2 col0\" >175014.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row3\" class=\"row_heading level0 row3\" rowspan=\"3\">云南</th>\n",
       "      <th id=\"T_2f85e_level1_row3\" class=\"row_heading level1 row3\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row3_col0\" class=\"data row3 col0\" >123051.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row4\" class=\"row_heading level1 row4\" >家具</th>\n",
       "      <td id=\"T_2f85e_row4_col0\" class=\"data row4 col0\" >174155.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row5\" class=\"row_heading level1 row5\" >技术</th>\n",
       "      <td id=\"T_2f85e_row5_col0\" class=\"data row5 col0\" >144512.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row6\" class=\"row_heading level0 row6\" rowspan=\"3\">内蒙古</th>\n",
       "      <th id=\"T_2f85e_level1_row6\" class=\"row_heading level1 row6\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row6_col0\" class=\"data row6 col0\" >74058.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row7\" class=\"row_heading level1 row7\" >家具</th>\n",
       "      <td id=\"T_2f85e_row7_col0\" class=\"data row7 col0\" >95426.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row8\" class=\"row_heading level1 row8\" >技术</th>\n",
       "      <td id=\"T_2f85e_row8_col0\" class=\"data row8 col0\" >80333.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row9\" class=\"row_heading level0 row9\" rowspan=\"3\">北京</th>\n",
       "      <th id=\"T_2f85e_level1_row9\" class=\"row_heading level1 row9\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row9_col0\" class=\"data row9 col0\" >144232.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row10\" class=\"row_heading level1 row10\" >家具</th>\n",
       "      <td id=\"T_2f85e_row10_col0\" class=\"data row10 col0\" >127407.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row11\" class=\"row_heading level1 row11\" >技术</th>\n",
       "      <td id=\"T_2f85e_row11_col0\" class=\"data row11 col0\" >78913.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row12\" class=\"row_heading level0 row12\" rowspan=\"3\">吉林</th>\n",
       "      <th id=\"T_2f85e_level1_row12\" class=\"row_heading level1 row12\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row12_col0\" class=\"data row12 col0\" >215143.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row13\" class=\"row_heading level1 row13\" >家具</th>\n",
       "      <td id=\"T_2f85e_row13_col0\" class=\"data row13 col0\" >287498.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row14\" class=\"row_heading level1 row14\" >技术</th>\n",
       "      <td id=\"T_2f85e_row14_col0\" class=\"data row14 col0\" >394083.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row15\" class=\"row_heading level0 row15\" rowspan=\"3\">四川</th>\n",
       "      <th id=\"T_2f85e_level1_row15\" class=\"row_heading level1 row15\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row15_col0\" class=\"data row15 col0\" >111393.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row16\" class=\"row_heading level1 row16\" >家具</th>\n",
       "      <td id=\"T_2f85e_row16_col0\" class=\"data row16 col0\" >88297.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row17\" class=\"row_heading level1 row17\" >技术</th>\n",
       "      <td id=\"T_2f85e_row17_col0\" class=\"data row17 col0\" >70095.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row18\" class=\"row_heading level0 row18\" rowspan=\"3\">天津</th>\n",
       "      <th id=\"T_2f85e_level1_row18\" class=\"row_heading level1 row18\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row18_col0\" class=\"data row18 col0\" >142526.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row19\" class=\"row_heading level1 row19\" >家具</th>\n",
       "      <td id=\"T_2f85e_row19_col0\" class=\"data row19 col0\" >149452.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row20\" class=\"row_heading level1 row20\" >技术</th>\n",
       "      <td id=\"T_2f85e_row20_col0\" class=\"data row20 col0\" >191384.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row21\" class=\"row_heading level0 row21\" rowspan=\"3\">宁夏</th>\n",
       "      <th id=\"T_2f85e_level1_row21\" class=\"row_heading level1 row21\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row21_col0\" class=\"data row21 col0\" >19529.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row22\" class=\"row_heading level1 row22\" >家具</th>\n",
       "      <td id=\"T_2f85e_row22_col0\" class=\"data row22 col0\" >16449.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row23\" class=\"row_heading level1 row23\" >技术</th>\n",
       "      <td id=\"T_2f85e_row23_col0\" class=\"data row23 col0\" >5314.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row24\" class=\"row_heading level0 row24\" rowspan=\"3\">安徽</th>\n",
       "      <th id=\"T_2f85e_level1_row24\" class=\"row_heading level1 row24\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row24_col0\" class=\"data row24 col0\" >200511.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row25\" class=\"row_heading level1 row25\" >家具</th>\n",
       "      <td id=\"T_2f85e_row25_col0\" class=\"data row25 col0\" >215901.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row26\" class=\"row_heading level1 row26\" >技术</th>\n",
       "      <td id=\"T_2f85e_row26_col0\" class=\"data row26 col0\" >267841.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row27\" class=\"row_heading level0 row27\" rowspan=\"3\">山东</th>\n",
       "      <th id=\"T_2f85e_level1_row27\" class=\"row_heading level1 row27\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row27_col0\" class=\"data row27 col0\" >575520.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row28\" class=\"row_heading level1 row28\" >家具</th>\n",
       "      <td id=\"T_2f85e_row28_col0\" class=\"data row28 col0\" >664339.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row29\" class=\"row_heading level1 row29\" >技术</th>\n",
       "      <td id=\"T_2f85e_row29_col0\" class=\"data row29 col0\" >644271.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row30\" class=\"row_heading level0 row30\" rowspan=\"3\">山西</th>\n",
       "      <th id=\"T_2f85e_level1_row30\" class=\"row_heading level1 row30\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row30_col0\" class=\"data row30 col0\" >121458.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row31\" class=\"row_heading level1 row31\" >家具</th>\n",
       "      <td id=\"T_2f85e_row31_col0\" class=\"data row31 col0\" >175522.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row32\" class=\"row_heading level1 row32\" >技术</th>\n",
       "      <td id=\"T_2f85e_row32_col0\" class=\"data row32 col0\" >132103.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row33\" class=\"row_heading level0 row33\" rowspan=\"3\">广东</th>\n",
       "      <th id=\"T_2f85e_level1_row33\" class=\"row_heading level1 row33\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row33_col0\" class=\"data row33 col0\" >494643.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row34\" class=\"row_heading level1 row34\" >家具</th>\n",
       "      <td id=\"T_2f85e_row34_col0\" class=\"data row34 col0\" >530054.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row35\" class=\"row_heading level1 row35\" >技术</th>\n",
       "      <td id=\"T_2f85e_row35_col0\" class=\"data row35 col0\" >495840.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row36\" class=\"row_heading level0 row36\" rowspan=\"3\">广西</th>\n",
       "      <th id=\"T_2f85e_level1_row36\" class=\"row_heading level1 row36\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row36_col0\" class=\"data row36 col0\" >102625.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row37\" class=\"row_heading level1 row37\" >家具</th>\n",
       "      <td id=\"T_2f85e_row37_col0\" class=\"data row37 col0\" >165140.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row38\" class=\"row_heading level1 row38\" >技术</th>\n",
       "      <td id=\"T_2f85e_row38_col0\" class=\"data row38 col0\" >115824.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row39\" class=\"row_heading level0 row39\" rowspan=\"3\">新疆</th>\n",
       "      <th id=\"T_2f85e_level1_row39\" class=\"row_heading level1 row39\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row39_col0\" class=\"data row39 col0\" >38345.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row40\" class=\"row_heading level1 row40\" >家具</th>\n",
       "      <td id=\"T_2f85e_row40_col0\" class=\"data row40 col0\" >20520.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row41\" class=\"row_heading level1 row41\" >技术</th>\n",
       "      <td id=\"T_2f85e_row41_col0\" class=\"data row41 col0\" >14059.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row42\" class=\"row_heading level0 row42\" rowspan=\"3\">江苏</th>\n",
       "      <th id=\"T_2f85e_level1_row42\" class=\"row_heading level1 row42\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row42_col0\" class=\"data row42 col0\" >163919.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row43\" class=\"row_heading level1 row43\" >家具</th>\n",
       "      <td id=\"T_2f85e_row43_col0\" class=\"data row43 col0\" >152868.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row44\" class=\"row_heading level1 row44\" >技术</th>\n",
       "      <td id=\"T_2f85e_row44_col0\" class=\"data row44 col0\" >85101.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row45\" class=\"row_heading level0 row45\" rowspan=\"3\">江西</th>\n",
       "      <th id=\"T_2f85e_level1_row45\" class=\"row_heading level1 row45\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row45_col0\" class=\"data row45 col0\" >37114.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row46\" class=\"row_heading level1 row46\" >家具</th>\n",
       "      <td id=\"T_2f85e_row46_col0\" class=\"data row46 col0\" >107047.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row47\" class=\"row_heading level1 row47\" >技术</th>\n",
       "      <td id=\"T_2f85e_row47_col0\" class=\"data row47 col0\" >78051.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row48\" class=\"row_heading level0 row48\" rowspan=\"3\">河北</th>\n",
       "      <th id=\"T_2f85e_level1_row48\" class=\"row_heading level1 row48\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row48_col0\" class=\"data row48 col0\" >284739.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row49\" class=\"row_heading level1 row49\" >家具</th>\n",
       "      <td id=\"T_2f85e_row49_col0\" class=\"data row49 col0\" >306535.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row50\" class=\"row_heading level1 row50\" >技术</th>\n",
       "      <td id=\"T_2f85e_row50_col0\" class=\"data row50 col0\" >307765.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row51\" class=\"row_heading level0 row51\" rowspan=\"3\">河南</th>\n",
       "      <th id=\"T_2f85e_level1_row51\" class=\"row_heading level1 row51\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row51_col0\" class=\"data row51 col0\" >266916.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row52\" class=\"row_heading level1 row52\" >家具</th>\n",
       "      <td id=\"T_2f85e_row52_col0\" class=\"data row52 col0\" >294593.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row53\" class=\"row_heading level1 row53\" >技术</th>\n",
       "      <td id=\"T_2f85e_row53_col0\" class=\"data row53 col0\" >368856.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row54\" class=\"row_heading level0 row54\" rowspan=\"3\">浙江</th>\n",
       "      <th id=\"T_2f85e_level1_row54\" class=\"row_heading level1 row54\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row54_col0\" class=\"data row54 col0\" >84471.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row55\" class=\"row_heading level1 row55\" >家具</th>\n",
       "      <td id=\"T_2f85e_row55_col0\" class=\"data row55 col0\" >84436.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row56\" class=\"row_heading level1 row56\" >技术</th>\n",
       "      <td id=\"T_2f85e_row56_col0\" class=\"data row56 col0\" >97854.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row57\" class=\"row_heading level0 row57\" rowspan=\"3\">海南</th>\n",
       "      <th id=\"T_2f85e_level1_row57\" class=\"row_heading level1 row57\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row57_col0\" class=\"data row57 col0\" >34141.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row58\" class=\"row_heading level1 row58\" >家具</th>\n",
       "      <td id=\"T_2f85e_row58_col0\" class=\"data row58 col0\" >41225.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row59\" class=\"row_heading level1 row59\" >技术</th>\n",
       "      <td id=\"T_2f85e_row59_col0\" class=\"data row59 col0\" >24509.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row60\" class=\"row_heading level0 row60\" rowspan=\"3\">湖北</th>\n",
       "      <th id=\"T_2f85e_level1_row60\" class=\"row_heading level1 row60\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row60_col0\" class=\"data row60 col0\" >112230.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row61\" class=\"row_heading level1 row61\" >家具</th>\n",
       "      <td id=\"T_2f85e_row61_col0\" class=\"data row61 col0\" >118053.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row62\" class=\"row_heading level1 row62\" >技术</th>\n",
       "      <td id=\"T_2f85e_row62_col0\" class=\"data row62 col0\" >177758.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row63\" class=\"row_heading level0 row63\" rowspan=\"3\">湖南</th>\n",
       "      <th id=\"T_2f85e_level1_row63\" class=\"row_heading level1 row63\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row63_col0\" class=\"data row63 col0\" >197969.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row64\" class=\"row_heading level1 row64\" >家具</th>\n",
       "      <td id=\"T_2f85e_row64_col0\" class=\"data row64 col0\" >241804.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row65\" class=\"row_heading level1 row65\" >技术</th>\n",
       "      <td id=\"T_2f85e_row65_col0\" class=\"data row65 col0\" >281893.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row66\" class=\"row_heading level0 row66\" rowspan=\"3\">甘肃</th>\n",
       "      <th id=\"T_2f85e_level1_row66\" class=\"row_heading level1 row66\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row66_col0\" class=\"data row66 col0\" >54012.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row67\" class=\"row_heading level1 row67\" >家具</th>\n",
       "      <td id=\"T_2f85e_row67_col0\" class=\"data row67 col0\" >68657.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row68\" class=\"row_heading level1 row68\" >技术</th>\n",
       "      <td id=\"T_2f85e_row68_col0\" class=\"data row68 col0\" >72884.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row69\" class=\"row_heading level0 row69\" rowspan=\"3\">福建</th>\n",
       "      <th id=\"T_2f85e_level1_row69\" class=\"row_heading level1 row69\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row69_col0\" class=\"data row69 col0\" >142728.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row70\" class=\"row_heading level1 row70\" >家具</th>\n",
       "      <td id=\"T_2f85e_row70_col0\" class=\"data row70 col0\" >243289.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row71\" class=\"row_heading level1 row71\" >技术</th>\n",
       "      <td id=\"T_2f85e_row71_col0\" class=\"data row71 col0\" >234055.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row72\" class=\"row_heading level0 row72\" >西藏</th>\n",
       "      <th id=\"T_2f85e_level1_row72\" class=\"row_heading level1 row72\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row72_col0\" class=\"data row72 col0\" >201.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row73\" class=\"row_heading level0 row73\" rowspan=\"3\">贵州</th>\n",
       "      <th id=\"T_2f85e_level1_row73\" class=\"row_heading level1 row73\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row73_col0\" class=\"data row73 col0\" >9713.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row74\" class=\"row_heading level1 row74\" >家具</th>\n",
       "      <td id=\"T_2f85e_row74_col0\" class=\"data row74 col0\" >29285.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row75\" class=\"row_heading level1 row75\" >技术</th>\n",
       "      <td id=\"T_2f85e_row75_col0\" class=\"data row75 col0\" >28023.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row76\" class=\"row_heading level0 row76\" rowspan=\"3\">辽宁</th>\n",
       "      <th id=\"T_2f85e_level1_row76\" class=\"row_heading level1 row76\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row76_col0\" class=\"data row76 col0\" >214994.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row77\" class=\"row_heading level1 row77\" >家具</th>\n",
       "      <td id=\"T_2f85e_row77_col0\" class=\"data row77 col0\" >270279.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row78\" class=\"row_heading level1 row78\" >技术</th>\n",
       "      <td id=\"T_2f85e_row78_col0\" class=\"data row78 col0\" >271404.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row79\" class=\"row_heading level0 row79\" rowspan=\"3\">重庆</th>\n",
       "      <th id=\"T_2f85e_level1_row79\" class=\"row_heading level1 row79\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row79_col0\" class=\"data row79 col0\" >71020.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row80\" class=\"row_heading level1 row80\" >家具</th>\n",
       "      <td id=\"T_2f85e_row80_col0\" class=\"data row80 col0\" >96318.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row81\" class=\"row_heading level1 row81\" >技术</th>\n",
       "      <td id=\"T_2f85e_row81_col0\" class=\"data row81 col0\" >116194.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row82\" class=\"row_heading level0 row82\" rowspan=\"3\">陕西</th>\n",
       "      <th id=\"T_2f85e_level1_row82\" class=\"row_heading level1 row82\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row82_col0\" class=\"data row82 col0\" >119169.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row83\" class=\"row_heading level1 row83\" >家具</th>\n",
       "      <td id=\"T_2f85e_row83_col0\" class=\"data row83 col0\" >187497.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row84\" class=\"row_heading level1 row84\" >技术</th>\n",
       "      <td id=\"T_2f85e_row84_col0\" class=\"data row84 col0\" >90142.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row85\" class=\"row_heading level0 row85\" rowspan=\"3\">青海</th>\n",
       "      <th id=\"T_2f85e_level1_row85\" class=\"row_heading level1 row85\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row85_col0\" class=\"data row85 col0\" >16718.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row86\" class=\"row_heading level1 row86\" >家具</th>\n",
       "      <td id=\"T_2f85e_row86_col0\" class=\"data row86 col0\" >25923.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row87\" class=\"row_heading level1 row87\" >技术</th>\n",
       "      <td id=\"T_2f85e_row87_col0\" class=\"data row87 col0\" >22896.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level0_row88\" class=\"row_heading level0 row88\" rowspan=\"3\">黑龙江</th>\n",
       "      <th id=\"T_2f85e_level1_row88\" class=\"row_heading level1 row88\" >办公用品</th>\n",
       "      <td id=\"T_2f85e_row88_col0\" class=\"data row88 col0\" >473319.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row89\" class=\"row_heading level1 row89\" >家具</th>\n",
       "      <td id=\"T_2f85e_row89_col0\" class=\"data row89 col0\" >497504.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_2f85e_level1_row90\" class=\"row_heading level1 row90\" >技术</th>\n",
       "      <td id=\"T_2f85e_row90_col0\" class=\"data row90 col0\" >375905.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x1b75d6ca520>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(['省/自治区', '类别'], as_index=False)['销售额'].sum().set_index(['省/自治区', '类别']).style.highlight_max()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 7 - 数据透视｜多层\n",
    "\n",
    "制作各省市「不同类别」产品的「销售总额」透视表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_d5ba4_row7_col1, #T_d5ba4_row7_col2, #T_d5ba4_row24_col0 {\n",
       "  background-color: #008800;\n",
       "}\n",
       "#T_d5ba4_row9_col0, #T_d5ba4_row9_col1, #T_d5ba4_row9_col2 {\n",
       "  background-color: yellow;\n",
       "}\n",
       "#T_d5ba4_row24_col1, #T_d5ba4_row24_col2 {\n",
       "  background-color: red;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_d5ba4_\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"index_name level0\" >类别</th>\n",
       "      <th class=\"col_heading level0 col0\" >办公用品</th>\n",
       "      <th class=\"col_heading level0 col1\" >家具</th>\n",
       "      <th class=\"col_heading level0 col2\" >技术</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th class=\"index_name level0\" >省/自治区</th>\n",
       "      <th class=\"blank col0\" >&nbsp;</th>\n",
       "      <th class=\"blank col1\" >&nbsp;</th>\n",
       "      <th class=\"blank col2\" >&nbsp;</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row0\" class=\"row_heading level0 row0\" >上海</th>\n",
       "      <td id=\"T_d5ba4_row0_col0\" class=\"data row0 col0\" >198529.000000</td>\n",
       "      <td id=\"T_d5ba4_row0_col1\" class=\"data row0 col1\" >221058.000000</td>\n",
       "      <td id=\"T_d5ba4_row0_col2\" class=\"data row0 col2\" >175014.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row1\" class=\"row_heading level0 row1\" >云南</th>\n",
       "      <td id=\"T_d5ba4_row1_col0\" class=\"data row1 col0\" >123051.000000</td>\n",
       "      <td id=\"T_d5ba4_row1_col1\" class=\"data row1 col1\" >174155.000000</td>\n",
       "      <td id=\"T_d5ba4_row1_col2\" class=\"data row1 col2\" >144512.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row2\" class=\"row_heading level0 row2\" >内蒙古</th>\n",
       "      <td id=\"T_d5ba4_row2_col0\" class=\"data row2 col0\" >74058.000000</td>\n",
       "      <td id=\"T_d5ba4_row2_col1\" class=\"data row2 col1\" >95426.000000</td>\n",
       "      <td id=\"T_d5ba4_row2_col2\" class=\"data row2 col2\" >80333.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row3\" class=\"row_heading level0 row3\" >北京</th>\n",
       "      <td id=\"T_d5ba4_row3_col0\" class=\"data row3 col0\" >144232.000000</td>\n",
       "      <td id=\"T_d5ba4_row3_col1\" class=\"data row3 col1\" >127407.000000</td>\n",
       "      <td id=\"T_d5ba4_row3_col2\" class=\"data row3 col2\" >78913.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row4\" class=\"row_heading level0 row4\" >吉林</th>\n",
       "      <td id=\"T_d5ba4_row4_col0\" class=\"data row4 col0\" >215143.000000</td>\n",
       "      <td id=\"T_d5ba4_row4_col1\" class=\"data row4 col1\" >287498.000000</td>\n",
       "      <td id=\"T_d5ba4_row4_col2\" class=\"data row4 col2\" >394083.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row5\" class=\"row_heading level0 row5\" >四川</th>\n",
       "      <td id=\"T_d5ba4_row5_col0\" class=\"data row5 col0\" >111393.000000</td>\n",
       "      <td id=\"T_d5ba4_row5_col1\" class=\"data row5 col1\" >88297.000000</td>\n",
       "      <td id=\"T_d5ba4_row5_col2\" class=\"data row5 col2\" >70095.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row6\" class=\"row_heading level0 row6\" >天津</th>\n",
       "      <td id=\"T_d5ba4_row6_col0\" class=\"data row6 col0\" >142526.000000</td>\n",
       "      <td id=\"T_d5ba4_row6_col1\" class=\"data row6 col1\" >149452.000000</td>\n",
       "      <td id=\"T_d5ba4_row6_col2\" class=\"data row6 col2\" >191384.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row7\" class=\"row_heading level0 row7\" >宁夏</th>\n",
       "      <td id=\"T_d5ba4_row7_col0\" class=\"data row7 col0\" >19529.000000</td>\n",
       "      <td id=\"T_d5ba4_row7_col1\" class=\"data row7 col1\" >16449.000000</td>\n",
       "      <td id=\"T_d5ba4_row7_col2\" class=\"data row7 col2\" >5314.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row8\" class=\"row_heading level0 row8\" >安徽</th>\n",
       "      <td id=\"T_d5ba4_row8_col0\" class=\"data row8 col0\" >200511.000000</td>\n",
       "      <td id=\"T_d5ba4_row8_col1\" class=\"data row8 col1\" >215901.000000</td>\n",
       "      <td id=\"T_d5ba4_row8_col2\" class=\"data row8 col2\" >267841.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row9\" class=\"row_heading level0 row9\" >山东</th>\n",
       "      <td id=\"T_d5ba4_row9_col0\" class=\"data row9 col0\" >575520.000000</td>\n",
       "      <td id=\"T_d5ba4_row9_col1\" class=\"data row9 col1\" >664339.000000</td>\n",
       "      <td id=\"T_d5ba4_row9_col2\" class=\"data row9 col2\" >644271.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row10\" class=\"row_heading level0 row10\" >山西</th>\n",
       "      <td id=\"T_d5ba4_row10_col0\" class=\"data row10 col0\" >121458.000000</td>\n",
       "      <td id=\"T_d5ba4_row10_col1\" class=\"data row10 col1\" >175522.000000</td>\n",
       "      <td id=\"T_d5ba4_row10_col2\" class=\"data row10 col2\" >132103.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row11\" class=\"row_heading level0 row11\" >广东</th>\n",
       "      <td id=\"T_d5ba4_row11_col0\" class=\"data row11 col0\" >494643.000000</td>\n",
       "      <td id=\"T_d5ba4_row11_col1\" class=\"data row11 col1\" >530054.000000</td>\n",
       "      <td id=\"T_d5ba4_row11_col2\" class=\"data row11 col2\" >495840.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row12\" class=\"row_heading level0 row12\" >广西</th>\n",
       "      <td id=\"T_d5ba4_row12_col0\" class=\"data row12 col0\" >102625.000000</td>\n",
       "      <td id=\"T_d5ba4_row12_col1\" class=\"data row12 col1\" >165140.000000</td>\n",
       "      <td id=\"T_d5ba4_row12_col2\" class=\"data row12 col2\" >115824.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row13\" class=\"row_heading level0 row13\" >新疆</th>\n",
       "      <td id=\"T_d5ba4_row13_col0\" class=\"data row13 col0\" >38345.000000</td>\n",
       "      <td id=\"T_d5ba4_row13_col1\" class=\"data row13 col1\" >20520.000000</td>\n",
       "      <td id=\"T_d5ba4_row13_col2\" class=\"data row13 col2\" >14059.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row14\" class=\"row_heading level0 row14\" >江苏</th>\n",
       "      <td id=\"T_d5ba4_row14_col0\" class=\"data row14 col0\" >163919.000000</td>\n",
       "      <td id=\"T_d5ba4_row14_col1\" class=\"data row14 col1\" >152868.000000</td>\n",
       "      <td id=\"T_d5ba4_row14_col2\" class=\"data row14 col2\" >85101.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row15\" class=\"row_heading level0 row15\" >江西</th>\n",
       "      <td id=\"T_d5ba4_row15_col0\" class=\"data row15 col0\" >37114.000000</td>\n",
       "      <td id=\"T_d5ba4_row15_col1\" class=\"data row15 col1\" >107047.000000</td>\n",
       "      <td id=\"T_d5ba4_row15_col2\" class=\"data row15 col2\" >78051.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row16\" class=\"row_heading level0 row16\" >河北</th>\n",
       "      <td id=\"T_d5ba4_row16_col0\" class=\"data row16 col0\" >284739.000000</td>\n",
       "      <td id=\"T_d5ba4_row16_col1\" class=\"data row16 col1\" >306535.000000</td>\n",
       "      <td id=\"T_d5ba4_row16_col2\" class=\"data row16 col2\" >307765.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row17\" class=\"row_heading level0 row17\" >河南</th>\n",
       "      <td id=\"T_d5ba4_row17_col0\" class=\"data row17 col0\" >266916.000000</td>\n",
       "      <td id=\"T_d5ba4_row17_col1\" class=\"data row17 col1\" >294593.000000</td>\n",
       "      <td id=\"T_d5ba4_row17_col2\" class=\"data row17 col2\" >368856.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row18\" class=\"row_heading level0 row18\" >浙江</th>\n",
       "      <td id=\"T_d5ba4_row18_col0\" class=\"data row18 col0\" >84471.000000</td>\n",
       "      <td id=\"T_d5ba4_row18_col1\" class=\"data row18 col1\" >84436.000000</td>\n",
       "      <td id=\"T_d5ba4_row18_col2\" class=\"data row18 col2\" >97854.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row19\" class=\"row_heading level0 row19\" >海南</th>\n",
       "      <td id=\"T_d5ba4_row19_col0\" class=\"data row19 col0\" >34141.000000</td>\n",
       "      <td id=\"T_d5ba4_row19_col1\" class=\"data row19 col1\" >41225.000000</td>\n",
       "      <td id=\"T_d5ba4_row19_col2\" class=\"data row19 col2\" >24509.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row20\" class=\"row_heading level0 row20\" >湖北</th>\n",
       "      <td id=\"T_d5ba4_row20_col0\" class=\"data row20 col0\" >112230.000000</td>\n",
       "      <td id=\"T_d5ba4_row20_col1\" class=\"data row20 col1\" >118053.000000</td>\n",
       "      <td id=\"T_d5ba4_row20_col2\" class=\"data row20 col2\" >177758.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row21\" class=\"row_heading level0 row21\" >湖南</th>\n",
       "      <td id=\"T_d5ba4_row21_col0\" class=\"data row21 col0\" >197969.000000</td>\n",
       "      <td id=\"T_d5ba4_row21_col1\" class=\"data row21 col1\" >241804.000000</td>\n",
       "      <td id=\"T_d5ba4_row21_col2\" class=\"data row21 col2\" >281893.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row22\" class=\"row_heading level0 row22\" >甘肃</th>\n",
       "      <td id=\"T_d5ba4_row22_col0\" class=\"data row22 col0\" >54012.000000</td>\n",
       "      <td id=\"T_d5ba4_row22_col1\" class=\"data row22 col1\" >68657.000000</td>\n",
       "      <td id=\"T_d5ba4_row22_col2\" class=\"data row22 col2\" >72884.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row23\" class=\"row_heading level0 row23\" >福建</th>\n",
       "      <td id=\"T_d5ba4_row23_col0\" class=\"data row23 col0\" >142728.000000</td>\n",
       "      <td id=\"T_d5ba4_row23_col1\" class=\"data row23 col1\" >243289.000000</td>\n",
       "      <td id=\"T_d5ba4_row23_col2\" class=\"data row23 col2\" >234055.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row24\" class=\"row_heading level0 row24\" >西藏</th>\n",
       "      <td id=\"T_d5ba4_row24_col0\" class=\"data row24 col0\" >201.000000</td>\n",
       "      <td id=\"T_d5ba4_row24_col1\" class=\"data row24 col1\" >nan</td>\n",
       "      <td id=\"T_d5ba4_row24_col2\" class=\"data row24 col2\" >nan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row25\" class=\"row_heading level0 row25\" >贵州</th>\n",
       "      <td id=\"T_d5ba4_row25_col0\" class=\"data row25 col0\" >9713.000000</td>\n",
       "      <td id=\"T_d5ba4_row25_col1\" class=\"data row25 col1\" >29285.000000</td>\n",
       "      <td id=\"T_d5ba4_row25_col2\" class=\"data row25 col2\" >28023.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row26\" class=\"row_heading level0 row26\" >辽宁</th>\n",
       "      <td id=\"T_d5ba4_row26_col0\" class=\"data row26 col0\" >214994.000000</td>\n",
       "      <td id=\"T_d5ba4_row26_col1\" class=\"data row26 col1\" >270279.000000</td>\n",
       "      <td id=\"T_d5ba4_row26_col2\" class=\"data row26 col2\" >271404.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row27\" class=\"row_heading level0 row27\" >重庆</th>\n",
       "      <td id=\"T_d5ba4_row27_col0\" class=\"data row27 col0\" >71020.000000</td>\n",
       "      <td id=\"T_d5ba4_row27_col1\" class=\"data row27 col1\" >96318.000000</td>\n",
       "      <td id=\"T_d5ba4_row27_col2\" class=\"data row27 col2\" >116194.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row28\" class=\"row_heading level0 row28\" >陕西</th>\n",
       "      <td id=\"T_d5ba4_row28_col0\" class=\"data row28 col0\" >119169.000000</td>\n",
       "      <td id=\"T_d5ba4_row28_col1\" class=\"data row28 col1\" >187497.000000</td>\n",
       "      <td id=\"T_d5ba4_row28_col2\" class=\"data row28 col2\" >90142.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row29\" class=\"row_heading level0 row29\" >青海</th>\n",
       "      <td id=\"T_d5ba4_row29_col0\" class=\"data row29 col0\" >16718.000000</td>\n",
       "      <td id=\"T_d5ba4_row29_col1\" class=\"data row29 col1\" >25923.000000</td>\n",
       "      <td id=\"T_d5ba4_row29_col2\" class=\"data row29 col2\" >22896.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_d5ba4_level0_row30\" class=\"row_heading level0 row30\" >黑龙江</th>\n",
       "      <td id=\"T_d5ba4_row30_col0\" class=\"data row30 col0\" >473319.000000</td>\n",
       "      <td id=\"T_d5ba4_row30_col1\" class=\"data row30 col1\" >497504.000000</td>\n",
       "      <td id=\"T_d5ba4_row30_col2\" class=\"data row30 col2\" >375905.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x1b890096dc0>"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(df.pivot_table(index='省/自治区', columns='类别', values='销售额',aggfunc=np.sum).style\n",
    "    .highlight_max()\n",
    "    .highlight_min(color=\"#008800\")\n",
    "    .highlight_null()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_ed6f9_row7_col1, #T_ed6f9_row7_col2, #T_ed6f9_row24_col0, #T_ed6f9_row24_col3 {\n",
       "  background-color: #008800;\n",
       "}\n",
       "#T_ed6f9_row9_col0, #T_ed6f9_row9_col1, #T_ed6f9_row9_col2, #T_ed6f9_row9_col3 {\n",
       "  background-color: yellow;\n",
       "}\n",
       "#T_ed6f9_row24_col1, #T_ed6f9_row24_col2 {\n",
       "  background-color: red;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_ed6f9_\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th class=\"col_heading level0 col0\" >办公用品</th>\n",
       "      <th class=\"col_heading level0 col1\" >家具</th>\n",
       "      <th class=\"col_heading level0 col2\" >技术</th>\n",
       "      <th class=\"col_heading level0 col3\" >销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th class=\"index_name level0\" >省/自治区</th>\n",
       "      <th class=\"blank col0\" >&nbsp;</th>\n",
       "      <th class=\"blank col1\" >&nbsp;</th>\n",
       "      <th class=\"blank col2\" >&nbsp;</th>\n",
       "      <th class=\"blank col3\" >&nbsp;</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row0\" class=\"row_heading level0 row0\" >上海</th>\n",
       "      <td id=\"T_ed6f9_row0_col0\" class=\"data row0 col0\" >198529.000000</td>\n",
       "      <td id=\"T_ed6f9_row0_col1\" class=\"data row0 col1\" >221058.000000</td>\n",
       "      <td id=\"T_ed6f9_row0_col2\" class=\"data row0 col2\" >175014.000000</td>\n",
       "      <td id=\"T_ed6f9_row0_col3\" class=\"data row0 col3\" >594601.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row1\" class=\"row_heading level0 row1\" >云南</th>\n",
       "      <td id=\"T_ed6f9_row1_col0\" class=\"data row1 col0\" >123051.000000</td>\n",
       "      <td id=\"T_ed6f9_row1_col1\" class=\"data row1 col1\" >174155.000000</td>\n",
       "      <td id=\"T_ed6f9_row1_col2\" class=\"data row1 col2\" >144512.000000</td>\n",
       "      <td id=\"T_ed6f9_row1_col3\" class=\"data row1 col3\" >441718.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row2\" class=\"row_heading level0 row2\" >内蒙古</th>\n",
       "      <td id=\"T_ed6f9_row2_col0\" class=\"data row2 col0\" >74058.000000</td>\n",
       "      <td id=\"T_ed6f9_row2_col1\" class=\"data row2 col1\" >95426.000000</td>\n",
       "      <td id=\"T_ed6f9_row2_col2\" class=\"data row2 col2\" >80333.000000</td>\n",
       "      <td id=\"T_ed6f9_row2_col3\" class=\"data row2 col3\" >249817.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row3\" class=\"row_heading level0 row3\" >北京</th>\n",
       "      <td id=\"T_ed6f9_row3_col0\" class=\"data row3 col0\" >144232.000000</td>\n",
       "      <td id=\"T_ed6f9_row3_col1\" class=\"data row3 col1\" >127407.000000</td>\n",
       "      <td id=\"T_ed6f9_row3_col2\" class=\"data row3 col2\" >78913.000000</td>\n",
       "      <td id=\"T_ed6f9_row3_col3\" class=\"data row3 col3\" >350552.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row4\" class=\"row_heading level0 row4\" >吉林</th>\n",
       "      <td id=\"T_ed6f9_row4_col0\" class=\"data row4 col0\" >215143.000000</td>\n",
       "      <td id=\"T_ed6f9_row4_col1\" class=\"data row4 col1\" >287498.000000</td>\n",
       "      <td id=\"T_ed6f9_row4_col2\" class=\"data row4 col2\" >394083.000000</td>\n",
       "      <td id=\"T_ed6f9_row4_col3\" class=\"data row4 col3\" >896724.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row5\" class=\"row_heading level0 row5\" >四川</th>\n",
       "      <td id=\"T_ed6f9_row5_col0\" class=\"data row5 col0\" >111393.000000</td>\n",
       "      <td id=\"T_ed6f9_row5_col1\" class=\"data row5 col1\" >88297.000000</td>\n",
       "      <td id=\"T_ed6f9_row5_col2\" class=\"data row5 col2\" >70095.000000</td>\n",
       "      <td id=\"T_ed6f9_row5_col3\" class=\"data row5 col3\" >269785.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row6\" class=\"row_heading level0 row6\" >天津</th>\n",
       "      <td id=\"T_ed6f9_row6_col0\" class=\"data row6 col0\" >142526.000000</td>\n",
       "      <td id=\"T_ed6f9_row6_col1\" class=\"data row6 col1\" >149452.000000</td>\n",
       "      <td id=\"T_ed6f9_row6_col2\" class=\"data row6 col2\" >191384.000000</td>\n",
       "      <td id=\"T_ed6f9_row6_col3\" class=\"data row6 col3\" >483362.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row7\" class=\"row_heading level0 row7\" >宁夏</th>\n",
       "      <td id=\"T_ed6f9_row7_col0\" class=\"data row7 col0\" >19529.000000</td>\n",
       "      <td id=\"T_ed6f9_row7_col1\" class=\"data row7 col1\" >16449.000000</td>\n",
       "      <td id=\"T_ed6f9_row7_col2\" class=\"data row7 col2\" >5314.000000</td>\n",
       "      <td id=\"T_ed6f9_row7_col3\" class=\"data row7 col3\" >41292.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row8\" class=\"row_heading level0 row8\" >安徽</th>\n",
       "      <td id=\"T_ed6f9_row8_col0\" class=\"data row8 col0\" >200511.000000</td>\n",
       "      <td id=\"T_ed6f9_row8_col1\" class=\"data row8 col1\" >215901.000000</td>\n",
       "      <td id=\"T_ed6f9_row8_col2\" class=\"data row8 col2\" >267841.000000</td>\n",
       "      <td id=\"T_ed6f9_row8_col3\" class=\"data row8 col3\" >684253.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row9\" class=\"row_heading level0 row9\" >山东</th>\n",
       "      <td id=\"T_ed6f9_row9_col0\" class=\"data row9 col0\" >575520.000000</td>\n",
       "      <td id=\"T_ed6f9_row9_col1\" class=\"data row9 col1\" >664339.000000</td>\n",
       "      <td id=\"T_ed6f9_row9_col2\" class=\"data row9 col2\" >644271.000000</td>\n",
       "      <td id=\"T_ed6f9_row9_col3\" class=\"data row9 col3\" >1884130.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row10\" class=\"row_heading level0 row10\" >山西</th>\n",
       "      <td id=\"T_ed6f9_row10_col0\" class=\"data row10 col0\" >121458.000000</td>\n",
       "      <td id=\"T_ed6f9_row10_col1\" class=\"data row10 col1\" >175522.000000</td>\n",
       "      <td id=\"T_ed6f9_row10_col2\" class=\"data row10 col2\" >132103.000000</td>\n",
       "      <td id=\"T_ed6f9_row10_col3\" class=\"data row10 col3\" >429083.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row11\" class=\"row_heading level0 row11\" >广东</th>\n",
       "      <td id=\"T_ed6f9_row11_col0\" class=\"data row11 col0\" >494643.000000</td>\n",
       "      <td id=\"T_ed6f9_row11_col1\" class=\"data row11 col1\" >530054.000000</td>\n",
       "      <td id=\"T_ed6f9_row11_col2\" class=\"data row11 col2\" >495840.000000</td>\n",
       "      <td id=\"T_ed6f9_row11_col3\" class=\"data row11 col3\" >1520537.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row12\" class=\"row_heading level0 row12\" >广西</th>\n",
       "      <td id=\"T_ed6f9_row12_col0\" class=\"data row12 col0\" >102625.000000</td>\n",
       "      <td id=\"T_ed6f9_row12_col1\" class=\"data row12 col1\" >165140.000000</td>\n",
       "      <td id=\"T_ed6f9_row12_col2\" class=\"data row12 col2\" >115824.000000</td>\n",
       "      <td id=\"T_ed6f9_row12_col3\" class=\"data row12 col3\" >383589.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row13\" class=\"row_heading level0 row13\" >新疆</th>\n",
       "      <td id=\"T_ed6f9_row13_col0\" class=\"data row13 col0\" >38345.000000</td>\n",
       "      <td id=\"T_ed6f9_row13_col1\" class=\"data row13 col1\" >20520.000000</td>\n",
       "      <td id=\"T_ed6f9_row13_col2\" class=\"data row13 col2\" >14059.000000</td>\n",
       "      <td id=\"T_ed6f9_row13_col3\" class=\"data row13 col3\" >72924.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row14\" class=\"row_heading level0 row14\" >江苏</th>\n",
       "      <td id=\"T_ed6f9_row14_col0\" class=\"data row14 col0\" >163919.000000</td>\n",
       "      <td id=\"T_ed6f9_row14_col1\" class=\"data row14 col1\" >152868.000000</td>\n",
       "      <td id=\"T_ed6f9_row14_col2\" class=\"data row14 col2\" >85101.000000</td>\n",
       "      <td id=\"T_ed6f9_row14_col3\" class=\"data row14 col3\" >401888.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row15\" class=\"row_heading level0 row15\" >江西</th>\n",
       "      <td id=\"T_ed6f9_row15_col0\" class=\"data row15 col0\" >37114.000000</td>\n",
       "      <td id=\"T_ed6f9_row15_col1\" class=\"data row15 col1\" >107047.000000</td>\n",
       "      <td id=\"T_ed6f9_row15_col2\" class=\"data row15 col2\" >78051.000000</td>\n",
       "      <td id=\"T_ed6f9_row15_col3\" class=\"data row15 col3\" >222212.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row16\" class=\"row_heading level0 row16\" >河北</th>\n",
       "      <td id=\"T_ed6f9_row16_col0\" class=\"data row16 col0\" >284739.000000</td>\n",
       "      <td id=\"T_ed6f9_row16_col1\" class=\"data row16 col1\" >306535.000000</td>\n",
       "      <td id=\"T_ed6f9_row16_col2\" class=\"data row16 col2\" >307765.000000</td>\n",
       "      <td id=\"T_ed6f9_row16_col3\" class=\"data row16 col3\" >899039.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row17\" class=\"row_heading level0 row17\" >河南</th>\n",
       "      <td id=\"T_ed6f9_row17_col0\" class=\"data row17 col0\" >266916.000000</td>\n",
       "      <td id=\"T_ed6f9_row17_col1\" class=\"data row17 col1\" >294593.000000</td>\n",
       "      <td id=\"T_ed6f9_row17_col2\" class=\"data row17 col2\" >368856.000000</td>\n",
       "      <td id=\"T_ed6f9_row17_col3\" class=\"data row17 col3\" >930365.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row18\" class=\"row_heading level0 row18\" >浙江</th>\n",
       "      <td id=\"T_ed6f9_row18_col0\" class=\"data row18 col0\" >84471.000000</td>\n",
       "      <td id=\"T_ed6f9_row18_col1\" class=\"data row18 col1\" >84436.000000</td>\n",
       "      <td id=\"T_ed6f9_row18_col2\" class=\"data row18 col2\" >97854.000000</td>\n",
       "      <td id=\"T_ed6f9_row18_col3\" class=\"data row18 col3\" >266761.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row19\" class=\"row_heading level0 row19\" >海南</th>\n",
       "      <td id=\"T_ed6f9_row19_col0\" class=\"data row19 col0\" >34141.000000</td>\n",
       "      <td id=\"T_ed6f9_row19_col1\" class=\"data row19 col1\" >41225.000000</td>\n",
       "      <td id=\"T_ed6f9_row19_col2\" class=\"data row19 col2\" >24509.000000</td>\n",
       "      <td id=\"T_ed6f9_row19_col3\" class=\"data row19 col3\" >99875.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row20\" class=\"row_heading level0 row20\" >湖北</th>\n",
       "      <td id=\"T_ed6f9_row20_col0\" class=\"data row20 col0\" >112230.000000</td>\n",
       "      <td id=\"T_ed6f9_row20_col1\" class=\"data row20 col1\" >118053.000000</td>\n",
       "      <td id=\"T_ed6f9_row20_col2\" class=\"data row20 col2\" >177758.000000</td>\n",
       "      <td id=\"T_ed6f9_row20_col3\" class=\"data row20 col3\" >408041.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row21\" class=\"row_heading level0 row21\" >湖南</th>\n",
       "      <td id=\"T_ed6f9_row21_col0\" class=\"data row21 col0\" >197969.000000</td>\n",
       "      <td id=\"T_ed6f9_row21_col1\" class=\"data row21 col1\" >241804.000000</td>\n",
       "      <td id=\"T_ed6f9_row21_col2\" class=\"data row21 col2\" >281893.000000</td>\n",
       "      <td id=\"T_ed6f9_row21_col3\" class=\"data row21 col3\" >721666.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row22\" class=\"row_heading level0 row22\" >甘肃</th>\n",
       "      <td id=\"T_ed6f9_row22_col0\" class=\"data row22 col0\" >54012.000000</td>\n",
       "      <td id=\"T_ed6f9_row22_col1\" class=\"data row22 col1\" >68657.000000</td>\n",
       "      <td id=\"T_ed6f9_row22_col2\" class=\"data row22 col2\" >72884.000000</td>\n",
       "      <td id=\"T_ed6f9_row22_col3\" class=\"data row22 col3\" >195553.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row23\" class=\"row_heading level0 row23\" >福建</th>\n",
       "      <td id=\"T_ed6f9_row23_col0\" class=\"data row23 col0\" >142728.000000</td>\n",
       "      <td id=\"T_ed6f9_row23_col1\" class=\"data row23 col1\" >243289.000000</td>\n",
       "      <td id=\"T_ed6f9_row23_col2\" class=\"data row23 col2\" >234055.000000</td>\n",
       "      <td id=\"T_ed6f9_row23_col3\" class=\"data row23 col3\" >620072.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row24\" class=\"row_heading level0 row24\" >西藏</th>\n",
       "      <td id=\"T_ed6f9_row24_col0\" class=\"data row24 col0\" >201.000000</td>\n",
       "      <td id=\"T_ed6f9_row24_col1\" class=\"data row24 col1\" >nan</td>\n",
       "      <td id=\"T_ed6f9_row24_col2\" class=\"data row24 col2\" >nan</td>\n",
       "      <td id=\"T_ed6f9_row24_col3\" class=\"data row24 col3\" >201.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row25\" class=\"row_heading level0 row25\" >贵州</th>\n",
       "      <td id=\"T_ed6f9_row25_col0\" class=\"data row25 col0\" >9713.000000</td>\n",
       "      <td id=\"T_ed6f9_row25_col1\" class=\"data row25 col1\" >29285.000000</td>\n",
       "      <td id=\"T_ed6f9_row25_col2\" class=\"data row25 col2\" >28023.000000</td>\n",
       "      <td id=\"T_ed6f9_row25_col3\" class=\"data row25 col3\" >67021.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row26\" class=\"row_heading level0 row26\" >辽宁</th>\n",
       "      <td id=\"T_ed6f9_row26_col0\" class=\"data row26 col0\" >214994.000000</td>\n",
       "      <td id=\"T_ed6f9_row26_col1\" class=\"data row26 col1\" >270279.000000</td>\n",
       "      <td id=\"T_ed6f9_row26_col2\" class=\"data row26 col2\" >271404.000000</td>\n",
       "      <td id=\"T_ed6f9_row26_col3\" class=\"data row26 col3\" >756677.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row27\" class=\"row_heading level0 row27\" >重庆</th>\n",
       "      <td id=\"T_ed6f9_row27_col0\" class=\"data row27 col0\" >71020.000000</td>\n",
       "      <td id=\"T_ed6f9_row27_col1\" class=\"data row27 col1\" >96318.000000</td>\n",
       "      <td id=\"T_ed6f9_row27_col2\" class=\"data row27 col2\" >116194.000000</td>\n",
       "      <td id=\"T_ed6f9_row27_col3\" class=\"data row27 col3\" >283532.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row28\" class=\"row_heading level0 row28\" >陕西</th>\n",
       "      <td id=\"T_ed6f9_row28_col0\" class=\"data row28 col0\" >119169.000000</td>\n",
       "      <td id=\"T_ed6f9_row28_col1\" class=\"data row28 col1\" >187497.000000</td>\n",
       "      <td id=\"T_ed6f9_row28_col2\" class=\"data row28 col2\" >90142.000000</td>\n",
       "      <td id=\"T_ed6f9_row28_col3\" class=\"data row28 col3\" >396808.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row29\" class=\"row_heading level0 row29\" >青海</th>\n",
       "      <td id=\"T_ed6f9_row29_col0\" class=\"data row29 col0\" >16718.000000</td>\n",
       "      <td id=\"T_ed6f9_row29_col1\" class=\"data row29 col1\" >25923.000000</td>\n",
       "      <td id=\"T_ed6f9_row29_col2\" class=\"data row29 col2\" >22896.000000</td>\n",
       "      <td id=\"T_ed6f9_row29_col3\" class=\"data row29 col3\" >65537.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_ed6f9_level0_row30\" class=\"row_heading level0 row30\" >黑龙江</th>\n",
       "      <td id=\"T_ed6f9_row30_col0\" class=\"data row30 col0\" >473319.000000</td>\n",
       "      <td id=\"T_ed6f9_row30_col1\" class=\"data row30 col1\" >497504.000000</td>\n",
       "      <td id=\"T_ed6f9_row30_col2\" class=\"data row30 col2\" >375905.000000</td>\n",
       "      <td id=\"T_ed6f9_row30_col3\" class=\"data row30 col3\" >1346728.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x1b891365190>"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(pd.concat( [ df.pivot_table(index='省/自治区', columns='类别', values='销售额',aggfunc=np.sum),\n",
    "    df.pivot_table(index='省/自治区', values='销售额',aggfunc=np.sum) ], axis=1).style\n",
    "    .highlight_max()\n",
    "    .highlight_min(color=\"#008800\")\n",
    "    .highlight_null()\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8 - 数据透视｜综合\n",
    "\n",
    "制作「各省市」、「不同类别」产品「销售量与销售额」的「均值与总和」的数据透视表，并在最后追加一行『合计』"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">mean</th>\n",
       "      <th colspan=\"2\" halign=\"left\">sum</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>数量</th>\n",
       "      <th>销售额</th>\n",
       "      <th>数量</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>省/自治区</th>\n",
       "      <th>类别</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">上海</th>\n",
       "      <th>办公用品</th>\n",
       "      <td>3.706897</td>\n",
       "      <td>1140.971264</td>\n",
       "      <td>645</td>\n",
       "      <td>198529.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>家具</th>\n",
       "      <td>4.132530</td>\n",
       "      <td>2663.349398</td>\n",
       "      <td>343</td>\n",
       "      <td>221058.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>技术</th>\n",
       "      <td>3.616667</td>\n",
       "      <td>2916.900000</td>\n",
       "      <td>217</td>\n",
       "      <td>175014.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">云南</th>\n",
       "      <th>办公用品</th>\n",
       "      <td>3.913043</td>\n",
       "      <td>891.673913</td>\n",
       "      <td>540</td>\n",
       "      <td>123051.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>家具</th>\n",
       "      <td>4.224490</td>\n",
       "      <td>3554.183673</td>\n",
       "      <td>207</td>\n",
       "      <td>174155.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">青海</th>\n",
       "      <th>家具</th>\n",
       "      <td>3.000000</td>\n",
       "      <td>3703.285714</td>\n",
       "      <td>21</td>\n",
       "      <td>25923.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>技术</th>\n",
       "      <td>3.833333</td>\n",
       "      <td>3816.000000</td>\n",
       "      <td>23</td>\n",
       "      <td>22896.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">黑龙江</th>\n",
       "      <th>办公用品</th>\n",
       "      <td>3.657471</td>\n",
       "      <td>1088.089655</td>\n",
       "      <td>1591</td>\n",
       "      <td>473319.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>家具</th>\n",
       "      <td>3.921687</td>\n",
       "      <td>2997.012048</td>\n",
       "      <td>651</td>\n",
       "      <td>497504.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>技术</th>\n",
       "      <td>3.442177</td>\n",
       "      <td>2557.176871</td>\n",
       "      <td>506</td>\n",
       "      <td>375905.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>91 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                mean                sum          \n",
       "                  数量          销售额    数量       销售额\n",
       "省/自治区 类别                                         \n",
       "上海    办公用品  3.706897  1140.971264   645  198529.0\n",
       "      家具    4.132530  2663.349398   343  221058.0\n",
       "      技术    3.616667  2916.900000   217  175014.0\n",
       "云南    办公用品  3.913043   891.673913   540  123051.0\n",
       "      家具    4.224490  3554.183673   207  174155.0\n",
       "...              ...          ...   ...       ...\n",
       "青海    家具    3.000000  3703.285714    21   25923.0\n",
       "      技术    3.833333  3816.000000    23   22896.0\n",
       "黑龙江   办公用品  3.657471  1088.089655  1591  473319.0\n",
       "      家具    3.921687  2997.012048   651  497504.0\n",
       "      技术    3.442177  2557.176871   506  375905.0\n",
       "\n",
       "[91 rows x 4 columns]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pivot_table(index=['省/自治区', '类别'], values=['数量', '销售额'],aggfunc=[np.mean, np.sum])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9 - 数据透视｜筛选\n",
    "\n",
    "在上一题的基础上，查询 **「类别」** 等于 **「办公用品」** 的详情"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style type=\"text/css\">\n",
       "#T_25ccb_row9_col2, #T_25ccb_row9_col3, #T_25ccb_row29_col0, #T_25ccb_row29_col1 {\n",
       "  background-color: yellow;\n",
       "}\n",
       "</style>\n",
       "<table id=\"T_25ccb_\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th class=\"blank\" >&nbsp;</th>\n",
       "      <th class=\"blank level0\" >&nbsp;</th>\n",
       "      <th class=\"col_heading level0 col0\" colspan=\"2\">mean</th>\n",
       "      <th class=\"col_heading level0 col2\" colspan=\"2\">sum</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th class=\"blank\" >&nbsp;</th>\n",
       "      <th class=\"blank level1\" >&nbsp;</th>\n",
       "      <th class=\"col_heading level1 col0\" >数量</th>\n",
       "      <th class=\"col_heading level1 col1\" >销售额</th>\n",
       "      <th class=\"col_heading level1 col2\" >数量</th>\n",
       "      <th class=\"col_heading level1 col3\" >销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th class=\"index_name level0\" >省/自治区</th>\n",
       "      <th class=\"index_name level1\" >类别</th>\n",
       "      <th class=\"blank col0\" >&nbsp;</th>\n",
       "      <th class=\"blank col1\" >&nbsp;</th>\n",
       "      <th class=\"blank col2\" >&nbsp;</th>\n",
       "      <th class=\"blank col3\" >&nbsp;</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row0\" class=\"row_heading level0 row0\" >上海</th>\n",
       "      <th id=\"T_25ccb_level1_row0\" class=\"row_heading level1 row0\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row0_col0\" class=\"data row0 col0\" >3.706897</td>\n",
       "      <td id=\"T_25ccb_row0_col1\" class=\"data row0 col1\" >1140.971264</td>\n",
       "      <td id=\"T_25ccb_row0_col2\" class=\"data row0 col2\" >645</td>\n",
       "      <td id=\"T_25ccb_row0_col3\" class=\"data row0 col3\" >198529.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row1\" class=\"row_heading level0 row1\" >云南</th>\n",
       "      <th id=\"T_25ccb_level1_row1\" class=\"row_heading level1 row1\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row1_col0\" class=\"data row1 col0\" >3.913043</td>\n",
       "      <td id=\"T_25ccb_row1_col1\" class=\"data row1 col1\" >891.673913</td>\n",
       "      <td id=\"T_25ccb_row1_col2\" class=\"data row1 col2\" >540</td>\n",
       "      <td id=\"T_25ccb_row1_col3\" class=\"data row1 col3\" >123051.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row2\" class=\"row_heading level0 row2\" >内蒙古</th>\n",
       "      <th id=\"T_25ccb_level1_row2\" class=\"row_heading level1 row2\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row2_col0\" class=\"data row2 col0\" >3.391304</td>\n",
       "      <td id=\"T_25ccb_row2_col1\" class=\"data row2 col1\" >643.982609</td>\n",
       "      <td id=\"T_25ccb_row2_col2\" class=\"data row2 col2\" >390</td>\n",
       "      <td id=\"T_25ccb_row2_col3\" class=\"data row2 col3\" >74058.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row3\" class=\"row_heading level0 row3\" >北京</th>\n",
       "      <th id=\"T_25ccb_level1_row3\" class=\"row_heading level1 row3\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row3_col0\" class=\"data row3 col0\" >3.750000</td>\n",
       "      <td id=\"T_25ccb_row3_col1\" class=\"data row3 col1\" >1163.161290</td>\n",
       "      <td id=\"T_25ccb_row3_col2\" class=\"data row3 col2\" >465</td>\n",
       "      <td id=\"T_25ccb_row3_col3\" class=\"data row3 col3\" >144232.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row4\" class=\"row_heading level0 row4\" >吉林</th>\n",
       "      <th id=\"T_25ccb_level1_row4\" class=\"row_heading level1 row4\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row4_col0\" class=\"data row4 col0\" >3.520270</td>\n",
       "      <td id=\"T_25ccb_row4_col1\" class=\"data row4 col1\" >726.834459</td>\n",
       "      <td id=\"T_25ccb_row4_col2\" class=\"data row4 col2\" >1042</td>\n",
       "      <td id=\"T_25ccb_row4_col3\" class=\"data row4 col3\" >215143.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row5\" class=\"row_heading level0 row5\" >四川</th>\n",
       "      <th id=\"T_25ccb_level1_row5\" class=\"row_heading level1 row5\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row5_col0\" class=\"data row5 col0\" >3.947368</td>\n",
       "      <td id=\"T_25ccb_row5_col1\" class=\"data row5 col1\" >837.541353</td>\n",
       "      <td id=\"T_25ccb_row5_col2\" class=\"data row5 col2\" >525</td>\n",
       "      <td id=\"T_25ccb_row5_col3\" class=\"data row5 col3\" >111393.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row6\" class=\"row_heading level0 row6\" >天津</th>\n",
       "      <th id=\"T_25ccb_level1_row6\" class=\"row_heading level1 row6\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row6_col0\" class=\"data row6 col0\" >3.917127</td>\n",
       "      <td id=\"T_25ccb_row6_col1\" class=\"data row6 col1\" >787.436464</td>\n",
       "      <td id=\"T_25ccb_row6_col2\" class=\"data row6 col2\" >709</td>\n",
       "      <td id=\"T_25ccb_row6_col3\" class=\"data row6 col3\" >142526.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row7\" class=\"row_heading level0 row7\" >宁夏</th>\n",
       "      <th id=\"T_25ccb_level1_row7\" class=\"row_heading level1 row7\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row7_col0\" class=\"data row7 col0\" >3.750000</td>\n",
       "      <td id=\"T_25ccb_row7_col1\" class=\"data row7 col1\" >1627.416667</td>\n",
       "      <td id=\"T_25ccb_row7_col2\" class=\"data row7 col2\" >45</td>\n",
       "      <td id=\"T_25ccb_row7_col3\" class=\"data row7 col3\" >19529.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row8\" class=\"row_heading level0 row8\" >安徽</th>\n",
       "      <th id=\"T_25ccb_level1_row8\" class=\"row_heading level1 row8\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row8_col0\" class=\"data row8 col0\" >3.710526</td>\n",
       "      <td id=\"T_25ccb_row8_col1\" class=\"data row8 col1\" >753.800752</td>\n",
       "      <td id=\"T_25ccb_row8_col2\" class=\"data row8 col2\" >987</td>\n",
       "      <td id=\"T_25ccb_row8_col3\" class=\"data row8 col3\" >200511.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row9\" class=\"row_heading level0 row9\" >山东</th>\n",
       "      <th id=\"T_25ccb_level1_row9\" class=\"row_heading level1 row9\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row9_col0\" class=\"data row9 col0\" >3.775112</td>\n",
       "      <td id=\"T_25ccb_row9_col1\" class=\"data row9 col1\" >862.848576</td>\n",
       "      <td id=\"T_25ccb_row9_col2\" class=\"data row9 col2\" >2518</td>\n",
       "      <td id=\"T_25ccb_row9_col3\" class=\"data row9 col3\" >575520.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row10\" class=\"row_heading level0 row10\" >山西</th>\n",
       "      <th id=\"T_25ccb_level1_row10\" class=\"row_heading level1 row10\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row10_col0\" class=\"data row10 col0\" >3.880597</td>\n",
       "      <td id=\"T_25ccb_row10_col1\" class=\"data row10 col1\" >906.402985</td>\n",
       "      <td id=\"T_25ccb_row10_col2\" class=\"data row10 col2\" >520</td>\n",
       "      <td id=\"T_25ccb_row10_col3\" class=\"data row10 col3\" >121458.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row11\" class=\"row_heading level0 row11\" >广东</th>\n",
       "      <th id=\"T_25ccb_level1_row11\" class=\"row_heading level1 row11\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row11_col0\" class=\"data row11 col0\" >3.908088</td>\n",
       "      <td id=\"T_25ccb_row11_col1\" class=\"data row11 col1\" >909.270221</td>\n",
       "      <td id=\"T_25ccb_row11_col2\" class=\"data row11 col2\" >2126</td>\n",
       "      <td id=\"T_25ccb_row11_col3\" class=\"data row11 col3\" >494643.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row12\" class=\"row_heading level0 row12\" >广西</th>\n",
       "      <th id=\"T_25ccb_level1_row12\" class=\"row_heading level1 row12\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row12_col0\" class=\"data row12 col0\" >3.954545</td>\n",
       "      <td id=\"T_25ccb_row12_col1\" class=\"data row12 col1\" >777.462121</td>\n",
       "      <td id=\"T_25ccb_row12_col2\" class=\"data row12 col2\" >522</td>\n",
       "      <td id=\"T_25ccb_row12_col3\" class=\"data row12 col3\" >102625.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row13\" class=\"row_heading level0 row13\" >新疆</th>\n",
       "      <th id=\"T_25ccb_level1_row13\" class=\"row_heading level1 row13\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row13_col0\" class=\"data row13 col0\" >3.575758</td>\n",
       "      <td id=\"T_25ccb_row13_col1\" class=\"data row13 col1\" >1161.969697</td>\n",
       "      <td id=\"T_25ccb_row13_col2\" class=\"data row13 col2\" >118</td>\n",
       "      <td id=\"T_25ccb_row13_col3\" class=\"data row13 col3\" >38345.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row14\" class=\"row_heading level0 row14\" >江苏</th>\n",
       "      <th id=\"T_25ccb_level1_row14\" class=\"row_heading level1 row14\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row14_col0\" class=\"data row14 col0\" >3.849741</td>\n",
       "      <td id=\"T_25ccb_row14_col1\" class=\"data row14 col1\" >849.321244</td>\n",
       "      <td id=\"T_25ccb_row14_col2\" class=\"data row14 col2\" >743</td>\n",
       "      <td id=\"T_25ccb_row14_col3\" class=\"data row14 col3\" >163919.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row15\" class=\"row_heading level0 row15\" >江西</th>\n",
       "      <th id=\"T_25ccb_level1_row15\" class=\"row_heading level1 row15\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row15_col0\" class=\"data row15 col0\" >3.523077</td>\n",
       "      <td id=\"T_25ccb_row15_col1\" class=\"data row15 col1\" >570.984615</td>\n",
       "      <td id=\"T_25ccb_row15_col2\" class=\"data row15 col2\" >229</td>\n",
       "      <td id=\"T_25ccb_row15_col3\" class=\"data row15 col3\" >37114.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row16\" class=\"row_heading level0 row16\" >河北</th>\n",
       "      <th id=\"T_25ccb_level1_row16\" class=\"row_heading level1 row16\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row16_col0\" class=\"data row16 col0\" >3.968750</td>\n",
       "      <td id=\"T_25ccb_row16_col1\" class=\"data row16 col1\" >988.677083</td>\n",
       "      <td id=\"T_25ccb_row16_col2\" class=\"data row16 col2\" >1143</td>\n",
       "      <td id=\"T_25ccb_row16_col3\" class=\"data row16 col3\" >284739.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row17\" class=\"row_heading level0 row17\" >河南</th>\n",
       "      <th id=\"T_25ccb_level1_row17\" class=\"row_heading level1 row17\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row17_col0\" class=\"data row17 col0\" >3.628242</td>\n",
       "      <td id=\"T_25ccb_row17_col1\" class=\"data row17 col1\" >769.210375</td>\n",
       "      <td id=\"T_25ccb_row17_col2\" class=\"data row17 col2\" >1259</td>\n",
       "      <td id=\"T_25ccb_row17_col3\" class=\"data row17 col3\" >266916.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row18\" class=\"row_heading level0 row18\" >浙江</th>\n",
       "      <th id=\"T_25ccb_level1_row18\" class=\"row_heading level1 row18\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row18_col0\" class=\"data row18 col0\" >3.684211</td>\n",
       "      <td id=\"T_25ccb_row18_col1\" class=\"data row18 col1\" >740.973684</td>\n",
       "      <td id=\"T_25ccb_row18_col2\" class=\"data row18 col2\" >420</td>\n",
       "      <td id=\"T_25ccb_row18_col3\" class=\"data row18 col3\" >84471.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row19\" class=\"row_heading level0 row19\" >海南</th>\n",
       "      <th id=\"T_25ccb_level1_row19\" class=\"row_heading level1 row19\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row19_col0\" class=\"data row19 col0\" >3.314286</td>\n",
       "      <td id=\"T_25ccb_row19_col1\" class=\"data row19 col1\" >975.457143</td>\n",
       "      <td id=\"T_25ccb_row19_col2\" class=\"data row19 col2\" >116</td>\n",
       "      <td id=\"T_25ccb_row19_col3\" class=\"data row19 col3\" >34141.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row20\" class=\"row_heading level0 row20\" >湖北</th>\n",
       "      <th id=\"T_25ccb_level1_row20\" class=\"row_heading level1 row20\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row20_col0\" class=\"data row20 col0\" >3.666667</td>\n",
       "      <td id=\"T_25ccb_row20_col1\" class=\"data row20 col1\" >645.000000</td>\n",
       "      <td id=\"T_25ccb_row20_col2\" class=\"data row20 col2\" >638</td>\n",
       "      <td id=\"T_25ccb_row20_col3\" class=\"data row20 col3\" >112230.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row21\" class=\"row_heading level0 row21\" >湖南</th>\n",
       "      <th id=\"T_25ccb_level1_row21\" class=\"row_heading level1 row21\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row21_col0\" class=\"data row21 col0\" >3.629771</td>\n",
       "      <td id=\"T_25ccb_row21_col1\" class=\"data row21 col1\" >755.606870</td>\n",
       "      <td id=\"T_25ccb_row21_col2\" class=\"data row21 col2\" >951</td>\n",
       "      <td id=\"T_25ccb_row21_col3\" class=\"data row21 col3\" >197969.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row22\" class=\"row_heading level0 row22\" >甘肃</th>\n",
       "      <th id=\"T_25ccb_level1_row22\" class=\"row_heading level1 row22\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row22_col0\" class=\"data row22 col0\" >4.206349</td>\n",
       "      <td id=\"T_25ccb_row22_col1\" class=\"data row22 col1\" >857.333333</td>\n",
       "      <td id=\"T_25ccb_row22_col2\" class=\"data row22 col2\" >265</td>\n",
       "      <td id=\"T_25ccb_row22_col3\" class=\"data row22 col3\" >54012.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row23\" class=\"row_heading level0 row23\" >福建</th>\n",
       "      <th id=\"T_25ccb_level1_row23\" class=\"row_heading level1 row23\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row23_col0\" class=\"data row23 col0\" >3.801047</td>\n",
       "      <td id=\"T_25ccb_row23_col1\" class=\"data row23 col1\" >747.267016</td>\n",
       "      <td id=\"T_25ccb_row23_col2\" class=\"data row23 col2\" >726</td>\n",
       "      <td id=\"T_25ccb_row23_col3\" class=\"data row23 col3\" >142728.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row24\" class=\"row_heading level0 row24\" >西藏</th>\n",
       "      <th id=\"T_25ccb_level1_row24\" class=\"row_heading level1 row24\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row24_col0\" class=\"data row24 col0\" >3.000000</td>\n",
       "      <td id=\"T_25ccb_row24_col1\" class=\"data row24 col1\" >201.000000</td>\n",
       "      <td id=\"T_25ccb_row24_col2\" class=\"data row24 col2\" >3</td>\n",
       "      <td id=\"T_25ccb_row24_col3\" class=\"data row24 col3\" >201.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row25\" class=\"row_heading level0 row25\" >贵州</th>\n",
       "      <th id=\"T_25ccb_level1_row25\" class=\"row_heading level1 row25\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row25_col0\" class=\"data row25 col0\" >3.954545</td>\n",
       "      <td id=\"T_25ccb_row25_col1\" class=\"data row25 col1\" >441.500000</td>\n",
       "      <td id=\"T_25ccb_row25_col2\" class=\"data row25 col2\" >87</td>\n",
       "      <td id=\"T_25ccb_row25_col3\" class=\"data row25 col3\" >9713.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row26\" class=\"row_heading level0 row26\" >辽宁</th>\n",
       "      <th id=\"T_25ccb_level1_row26\" class=\"row_heading level1 row26\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row26_col0\" class=\"data row26 col0\" >3.741722</td>\n",
       "      <td id=\"T_25ccb_row26_col1\" class=\"data row26 col1\" >711.900662</td>\n",
       "      <td id=\"T_25ccb_row26_col2\" class=\"data row26 col2\" >1130</td>\n",
       "      <td id=\"T_25ccb_row26_col3\" class=\"data row26 col3\" >214994.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row27\" class=\"row_heading level0 row27\" >重庆</th>\n",
       "      <th id=\"T_25ccb_level1_row27\" class=\"row_heading level1 row27\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row27_col0\" class=\"data row27 col0\" >3.876106</td>\n",
       "      <td id=\"T_25ccb_row27_col1\" class=\"data row27 col1\" >628.495575</td>\n",
       "      <td id=\"T_25ccb_row27_col2\" class=\"data row27 col2\" >438</td>\n",
       "      <td id=\"T_25ccb_row27_col3\" class=\"data row27 col3\" >71020.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row28\" class=\"row_heading level0 row28\" >陕西</th>\n",
       "      <th id=\"T_25ccb_level1_row28\" class=\"row_heading level1 row28\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row28_col0\" class=\"data row28 col0\" >3.816667</td>\n",
       "      <td id=\"T_25ccb_row28_col1\" class=\"data row28 col1\" >993.075000</td>\n",
       "      <td id=\"T_25ccb_row28_col2\" class=\"data row28 col2\" >458</td>\n",
       "      <td id=\"T_25ccb_row28_col3\" class=\"data row28 col3\" >119169.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row29\" class=\"row_heading level0 row29\" >青海</th>\n",
       "      <th id=\"T_25ccb_level1_row29\" class=\"row_heading level1 row29\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row29_col0\" class=\"data row29 col0\" >4.444444</td>\n",
       "      <td id=\"T_25ccb_row29_col1\" class=\"data row29 col1\" >1857.555556</td>\n",
       "      <td id=\"T_25ccb_row29_col2\" class=\"data row29 col2\" >40</td>\n",
       "      <td id=\"T_25ccb_row29_col3\" class=\"data row29 col3\" >16718.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th id=\"T_25ccb_level0_row30\" class=\"row_heading level0 row30\" >黑龙江</th>\n",
       "      <th id=\"T_25ccb_level1_row30\" class=\"row_heading level1 row30\" >办公用品</th>\n",
       "      <td id=\"T_25ccb_row30_col0\" class=\"data row30 col0\" >3.657471</td>\n",
       "      <td id=\"T_25ccb_row30_col1\" class=\"data row30 col1\" >1088.089655</td>\n",
       "      <td id=\"T_25ccb_row30_col2\" class=\"data row30 col2\" >1591</td>\n",
       "      <td id=\"T_25ccb_row30_col3\" class=\"data row30 col3\" >473319.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x1b891365400>"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pivot_table(index=['省/自治区', '类别'], values=['数量', '销售额'],aggfunc=[np.mean, np.sum]).loc[(slice(None), '办公用品'),:].style.highlight_max()\n",
    "#df.pivot_table(index=['省/自治区', '类别'], values=['数量', '销售额'],aggfunc=[np.mean, np.sum]).query('类别 == \"办公用品\"')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 10 -数据透视｜逆透视"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "逆透视就是将宽的表转换为长的表，例如将第 5 题的透视表进行逆透视，其中不需要转换的列为『数量』列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "# df.pivot_table(index='省/自治区', values=['销售额', '利润'], aggfunc=[np.sum])\n",
    "# df.melt(id_vars='数量',value_vars=[ '销售额', '利润'])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据合并"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### concat - 数据拼接"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`concat`主要用于**数据拼接**，也是非常常用的一个操作\n",
    "\n",
    "除了官方文档外很难找到比官方文档更好的练习\n",
    "\n",
    "以下案例来源或基于 [👉官方文档](https://pandas.pydata.org/pandas-docs/version/0.20/merging.html) 中的案例修改而来\n",
    "\n",
    "在练习之前应执行下方代码生成数据\n",
    "\n",
    "并应预览不同数据的结构以及每题的图解（如果有）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],\n",
    "                    'B': ['B0', 'B1', 'B2', 'B3'],\n",
    "                    'C': ['C0', 'C1', 'C2', 'C3'],\n",
    "                    'D': ['D0', 'D1', 'D2', 'D3']},\n",
    "                   index=[0, 1, 2, 3])\n",
    "\n",
    "\n",
    "df2 = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'],\n",
    "                    'B': ['B4', 'B5', 'B6', 'B7'],\n",
    "                    'C': ['C4', 'C5', 'C6', 'C7'],\n",
    "                    'D': ['D4', 'D5', 'D6', 'D7']},\n",
    "                   index=[4, 5, 6, 7])\n",
    "\n",
    "\n",
    "df3 = pd.DataFrame({'A': ['A8', 'A9', 'A10', 'A11'],\n",
    "                    'B': ['B8', 'B9', 'B10', 'B11'],\n",
    "                    'C': ['C8', 'C9', 'C10', 'C11'],\n",
    "                    'D': ['D8', 'D9', 'D10', 'D11']},\n",
    "                   index=[8, 9, 10, 11])\n",
    "\n",
    "\n",
    "df4 = pd.DataFrame({'B': ['B2', 'B3', 'B6', 'B7'],\n",
    "                    'D': ['D2', 'D3', 'D6', 'D7'],\n",
    "                    'F': ['F2', 'F3', 'F6', 'F7']},\n",
    "                   index=[2, 3, 6, 7])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B   C   D\n",
       "0  A0  B0  C0  D0\n",
       "1  A1  B1  C1  D1\n",
       "2  A2  B2  C2  D2\n",
       "3  A3  B3  C3  D3"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A4</td>\n",
       "      <td>B4</td>\n",
       "      <td>C4</td>\n",
       "      <td>D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>A5</td>\n",
       "      <td>B5</td>\n",
       "      <td>C5</td>\n",
       "      <td>D5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A6</td>\n",
       "      <td>B6</td>\n",
       "      <td>C6</td>\n",
       "      <td>D6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>A7</td>\n",
       "      <td>B7</td>\n",
       "      <td>C7</td>\n",
       "      <td>D7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B   C   D\n",
       "4  A4  B4  C4  D4\n",
       "5  A5  B5  C5  D5\n",
       "6  A6  B6  C6  D6\n",
       "7  A7  B7  C7  D7"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>A8</td>\n",
       "      <td>B8</td>\n",
       "      <td>C8</td>\n",
       "      <td>D8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>A9</td>\n",
       "      <td>B9</td>\n",
       "      <td>C9</td>\n",
       "      <td>D9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>A10</td>\n",
       "      <td>B10</td>\n",
       "      <td>C10</td>\n",
       "      <td>D10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>A11</td>\n",
       "      <td>B11</td>\n",
       "      <td>C11</td>\n",
       "      <td>D11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      A    B    C    D\n",
       "8    A8   B8   C8   D8\n",
       "9    A9   B9   C9   D9\n",
       "10  A10  B10  C10  D10\n",
       "11  A11  B11  C11  D11"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>B</th>\n",
       "      <th>D</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>B2</td>\n",
       "      <td>D2</td>\n",
       "      <td>F2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>B3</td>\n",
       "      <td>D3</td>\n",
       "      <td>F3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>B6</td>\n",
       "      <td>D6</td>\n",
       "      <td>F6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>B7</td>\n",
       "      <td>D7</td>\n",
       "      <td>F7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    B   D   F\n",
       "2  B2  D2  F2\n",
       "3  B3  D3  F3\n",
       "6  B6  D6  F6\n",
       "7  B7  D7  F7"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 11 - <font color = '#FB8E00'>concat</font>｜默认拼接\n",
    "\n",
    "拼接 df1 和 df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A4</td>\n",
       "      <td>B4</td>\n",
       "      <td>C4</td>\n",
       "      <td>D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>A5</td>\n",
       "      <td>B5</td>\n",
       "      <td>C5</td>\n",
       "      <td>D5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A6</td>\n",
       "      <td>B6</td>\n",
       "      <td>C6</td>\n",
       "      <td>D6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>A7</td>\n",
       "      <td>B7</td>\n",
       "      <td>C7</td>\n",
       "      <td>D7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B   C   D\n",
       "0  A0  B0  C0  D0\n",
       "1  A1  B1  C1  D1\n",
       "2  A2  B2  C2  D2\n",
       "3  A3  B3  C3  D3\n",
       "4  A4  B4  C4  D4\n",
       "5  A5  B5  C5  D5\n",
       "6  A6  B6  C6  D6\n",
       "7  A7  B7  C7  D7"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1, df2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 12 - <font color = '#FB8E00'>concat</font>｜拼接多个\n",
    "\n",
    "垂直拼接 `df1、df2、df3`，效果如下图所示\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_concat_basic.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A4</td>\n",
       "      <td>B4</td>\n",
       "      <td>C4</td>\n",
       "      <td>D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>A5</td>\n",
       "      <td>B5</td>\n",
       "      <td>C5</td>\n",
       "      <td>D5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A6</td>\n",
       "      <td>B6</td>\n",
       "      <td>C6</td>\n",
       "      <td>D6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>A7</td>\n",
       "      <td>B7</td>\n",
       "      <td>C7</td>\n",
       "      <td>D7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>A8</td>\n",
       "      <td>B8</td>\n",
       "      <td>C8</td>\n",
       "      <td>D8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>A9</td>\n",
       "      <td>B9</td>\n",
       "      <td>C9</td>\n",
       "      <td>D9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>A10</td>\n",
       "      <td>B10</td>\n",
       "      <td>C10</td>\n",
       "      <td>D10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>A11</td>\n",
       "      <td>B11</td>\n",
       "      <td>C11</td>\n",
       "      <td>D11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      A    B    C    D\n",
       "0    A0   B0   C0   D0\n",
       "1    A1   B1   C1   D1\n",
       "2    A2   B2   C2   D2\n",
       "3    A3   B3   C3   D3\n",
       "4    A4   B4   C4   D4\n",
       "5    A5   B5   C5   D5\n",
       "6    A6   B6   C6   D6\n",
       "7    A7   B7   C7   D7\n",
       "8    A8   B8   C8   D8\n",
       "9    A9   B9   C9   D9\n",
       "10  A10  B10  C10  D10\n",
       "11  A11  B11  C11  D11"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1, df2, df3])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 13 - <font color = '#FB8E00'>concat</font>｜重置索引\n",
    "\n",
    "垂直拼接 df1 和 df4，并按顺序重新生成索引，\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_concat_ignore_index.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NaN</td>\n",
       "      <td>B2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>D2</td>\n",
       "      <td>F2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>B3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>D3</td>\n",
       "      <td>F3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>B6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>D6</td>\n",
       "      <td>F6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>NaN</td>\n",
       "      <td>B7</td>\n",
       "      <td>NaN</td>\n",
       "      <td>D7</td>\n",
       "      <td>F7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A   B    C   D    F\n",
       "0   A0  B0   C0  D0  NaN\n",
       "1   A1  B1   C1  D1  NaN\n",
       "2   A2  B2   C2  D2  NaN\n",
       "3   A3  B3   C3  D3  NaN\n",
       "2  NaN  B2  NaN  D2   F2\n",
       "3  NaN  B3  NaN  D3   F3\n",
       "6  NaN  B6  NaN  D6   F6\n",
       "7  NaN  B7  NaN  D7   F7"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1, df4])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 14 - <font color = '#FB8E00'>concat</font>｜横向拼接\n",
    "\n",
    "横向拼接 `df1、df4`，效果如下图所示\n",
    "\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_concat_axis1.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>B</th>\n",
       "      <th>D</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "      <td>B2</td>\n",
       "      <td>D2</td>\n",
       "      <td>F2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "      <td>B3</td>\n",
       "      <td>D3</td>\n",
       "      <td>F3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>B6</td>\n",
       "      <td>D6</td>\n",
       "      <td>F6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>B7</td>\n",
       "      <td>D7</td>\n",
       "      <td>F7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A    B    C    D    B    D    F\n",
       "0   A0   B0   C0   D0  NaN  NaN  NaN\n",
       "1   A1   B1   C1   D1  NaN  NaN  NaN\n",
       "2   A2   B2   C2   D2   B2   D2   F2\n",
       "3   A3   B3   C3   D3   B3   D3   F3\n",
       "6  NaN  NaN  NaN  NaN   B6   D6   F6\n",
       "7  NaN  NaN  NaN  NaN   B7   D7   F7"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1, df4], axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![公众号：早起Python](http://liuzaoqi.oss-cn-beijing.aliyuncs.com/2021/09/18/16319660121648.jpg?域名/sample.jpg?x-oss-process=style/stylename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>B</th>\n",
       "      <th>D</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "      <td>B2</td>\n",
       "      <td>D2</td>\n",
       "      <td>F2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "      <td>B3</td>\n",
       "      <td>D3</td>\n",
       "      <td>F3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B   C   D   B   D   F\n",
       "2  A2  B2  C2  D2  B2  D2  F2\n",
       "3  A3  B3  C3  D3  B3  D3  F3"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 15 - <font color = '#FB8E00'>concat</font>｜横向拼接（取交集）\n",
    "\n",
    "在上一题的基础上，只取结果的交集\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_concat_axis1_inner.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>B</th>\n",
       "      <th>D</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "      <td>B2</td>\n",
       "      <td>D2</td>\n",
       "      <td>F2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "      <td>B3</td>\n",
       "      <td>D3</td>\n",
       "      <td>F3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B   C   D   B   D   F\n",
       "2  A2  B2  C2  D2  B2  D2  F2\n",
       "3  A3  B3  C3  D3  B3  D3  F3"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1, df4], join='inner', axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "微信搜索公众号「早起Python」，关注后可以获得更多资源！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 16 - <font color = '#FB8E00'>concat</font>｜横向拼接（取指定）\n",
    "\n",
    "在 14 题基础上，只取包含 df1 索引的部分\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_concat_axis1_join_axes.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>B</th>\n",
       "      <th>D</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "      <td>B2</td>\n",
       "      <td>D2</td>\n",
       "      <td>F2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "      <td>B3</td>\n",
       "      <td>D3</td>\n",
       "      <td>F3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>B6</td>\n",
       "      <td>D6</td>\n",
       "      <td>F6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>B7</td>\n",
       "      <td>D7</td>\n",
       "      <td>F7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A    B    C    D    B    D    F\n",
       "0   A0   B0   C0   D0  NaN  NaN  NaN\n",
       "1   A1   B1   C1   D1  NaN  NaN  NaN\n",
       "2   A2   B2   C2   D2   B2   D2   F2\n",
       "3   A3   B3   C3   D3   B3   D3   F3\n",
       "6  NaN  NaN  NaN  NaN   B6   D6   F6\n",
       "7  NaN  NaN  NaN  NaN   B7   D7   F7"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 新片没有 join_axes 参数了，只能用merge left join来做\n",
    "pd.concat([df1, df4], axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 17 - <font color = '#FB8E00'>concat</font>｜新增索引\n",
    "\n",
    "拼接 `df1、df2、df3`，同时新增一个索引（`x、y、z`）来区分不同的表数据来源\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_concat_keys.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">x</th>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">y</th>\n",
       "      <th>4</th>\n",
       "      <td>A4</td>\n",
       "      <td>B4</td>\n",
       "      <td>C4</td>\n",
       "      <td>D4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>A5</td>\n",
       "      <td>B5</td>\n",
       "      <td>C5</td>\n",
       "      <td>D5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>A6</td>\n",
       "      <td>B6</td>\n",
       "      <td>C6</td>\n",
       "      <td>D6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>A7</td>\n",
       "      <td>B7</td>\n",
       "      <td>C7</td>\n",
       "      <td>D7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">z</th>\n",
       "      <th>8</th>\n",
       "      <td>A8</td>\n",
       "      <td>B8</td>\n",
       "      <td>C8</td>\n",
       "      <td>D8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>A9</td>\n",
       "      <td>B9</td>\n",
       "      <td>C9</td>\n",
       "      <td>D9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>A10</td>\n",
       "      <td>B10</td>\n",
       "      <td>C10</td>\n",
       "      <td>D10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>A11</td>\n",
       "      <td>B11</td>\n",
       "      <td>C11</td>\n",
       "      <td>D11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        A    B    C    D\n",
       "x 0    A0   B0   C0   D0\n",
       "  1    A1   B1   C1   D1\n",
       "  2    A2   B2   C2   D2\n",
       "  3    A3   B3   C3   D3\n",
       "y 4    A4   B4   C4   D4\n",
       "  5    A5   B5   C5   D5\n",
       "  6    A6   B6   C6   D6\n",
       "  7    A7   B7   C7   D7\n",
       "z 8    A8   B8   C8   D8\n",
       "  9    A9   B9   C9   D9\n",
       "  10  A10  B10  C10  D10\n",
       "  11  A11  B11  C11  D11"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1, df2, df3], keys=['x','y','z'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### merge - 数据连接"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "concat是拼接，merge则是连接，同样重要的一个操作\n",
    "\n",
    "同样很难找到比官方文档更好的练习，以下案例来源或基于 [👉官方文档](https://pandas.pydata.org/pandas-docs/version/0.20/merging.html#database-style-dataframe-joining-merging) 中的案例修改而来\n",
    "\n",
    "在练习之前应执行每题下方的代码生成数据\n",
    "\n",
    "并应预览不同数据的结构以及每题的图解（如果有）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 18 - <font color = '#1B85FF' >merge</font>｜按单键\n",
    "\n",
    "根据 `key` 连接 `left` 和 `right`\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_merge_on_key.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "left = pd.DataFrame({'key': ['K0', 'K1', 'K2', 'K3'],\n",
    "                     'A': ['A0', 'A1', 'A2', 'A3'],\n",
    "                     'B': ['B0', 'B1', 'B2', 'B3']})\n",
    "\n",
    "right = pd.DataFrame({'key': ['K0', 'K1', 'K2', 'K3'],\n",
    "                      'C': ['C0', 'C1', 'C2', 'C3'],\n",
    "                      'D': ['D0', 'D1', 'D2', 'D3']})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>K3</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  key   C   D\n",
       "0  K0  C0  D0\n",
       "1  K1  C1  D1\n",
       "2  K2  C2  D2\n",
       "3  K3  C3  D3"
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "right"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 19 - <font color = '#1B85FF' >merge</font>｜按多键\n",
    "\n",
    "根据 `key1` 和 `key2` 连接 `left` 和 `right`\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_merge_on_key_multiple.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "left = pd.DataFrame({'key1': ['K0', 'K0', 'K1', 'K2'],\n",
    "                     'key2': ['K0', 'K1', 'K0', 'K1'],\n",
    "                     'A': ['A0', 'A1', 'A2', 'A3'],\n",
    "                     'B': ['B0', 'B1', 'B2', 'B3']})\n",
    "\n",
    "\n",
    "right = pd.DataFrame({'key1': ['K0', 'K1', 'K1', 'K2'],\n",
    "                      'key2': ['K0', 'K0', 'K0', 'K0'],\n",
    "                      'C': ['C0', 'C1', 'C2', 'C3'],\n",
    "                      'D': ['D0', 'D1', 'D2', 'D3']})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key1</th>\n",
       "      <th>key2</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>K0</td>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  key1 key2   A   B   C   D\n",
       "0   K0   K0  A0  B0  C0  D0\n",
       "1   K1   K0  A2  B2  C1  D1\n",
       "2   K1   K0  A2  B2  C2  D2"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(left=left, right=right )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 20 - <font color = '#1B85FF' >merge</font>｜左外连接\n",
    "\n",
    "\n",
    "如下图所示的结果连接 left 和 right，保留左表全部键\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_merge_on_key_left.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key1</th>\n",
       "      <th>key2</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>K0</td>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K0</td>\n",
       "      <td>K1</td>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>K2</td>\n",
       "      <td>K1</td>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  key1 key2   A   B    C    D\n",
       "0   K0   K0  A0  B0   C0   D0\n",
       "1   K0   K1  A1  B1  NaN  NaN\n",
       "2   K1   K0  A2  B2   C1   D1\n",
       "3   K1   K0  A2  B2   C2   D2\n",
       "4   K2   K1  A3  B3  NaN  NaN"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(left=left, right=right, how='left')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 21 - <font color = '#1B85FF' >merge</font>｜右外连接\n",
    "\n",
    "\n",
    "如下图所示的结果连接 left 和 right，保留右表全部键\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_merge_on_key_right.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key1</th>\n",
       "      <th>key2</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>K0</td>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>K2</td>\n",
       "      <td>K0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  key1 key2    A    B   C   D\n",
       "0   K0   K0   A0   B0  C0  D0\n",
       "1   K1   K0   A2   B2  C1  D1\n",
       "2   K1   K0   A2   B2  C2  D2\n",
       "3   K2   K0  NaN  NaN  C3  D3"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(left=left, right=right, how='right')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 22 - <font color = '#1B85FF' >merge</font>｜全外连接\n",
    "\n",
    "\n",
    "如下图所示的结果连接 left 和 right，保留全部键\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_merge_on_key_outer.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key1</th>\n",
       "      <th>key2</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>K0</td>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K0</td>\n",
       "      <td>K1</td>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>K2</td>\n",
       "      <td>K1</td>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>K2</td>\n",
       "      <td>K0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  key1 key2    A    B    C    D\n",
       "0   K0   K0   A0   B0   C0   D0\n",
       "1   K0   K1   A1   B1  NaN  NaN\n",
       "2   K1   K0   A2   B2   C1   D1\n",
       "3   K1   K0   A2   B2   C2   D2\n",
       "4   K2   K1   A3   B3  NaN  NaN\n",
       "5   K2   K0  NaN  NaN   C3   D3"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(left=left, right=right, how='outer')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 23 - <font color = '#1B85FF' >merge</font>｜内连接\n",
    "\n",
    "\n",
    "如下图所示的结果连接 left 和 right，保留交集\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_merge_on_key_inner.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key1</th>\n",
       "      <th>key2</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>K0</td>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  key1 key2   A   B   C   D\n",
       "0   K0   K0  A0  B0  C0  D0\n",
       "1   K1   K0  A2  B2  C1  D1\n",
       "2   K1   K0  A2  B2  C2  D2"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(left=left, right=right, how='inner' )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 24 - <font color = '#1B85FF' >merge</font>｜重复索引\n",
    "\n",
    "\n",
    "重新产生数据并按下图所示进行连接\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_merge_overlapped_suffix.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "left = pd.DataFrame({'k': ['K0', 'K1', 'K2'], 'v': [1, 2, 3]})\n",
    "\n",
    "right = pd.DataFrame({'k': ['K0', 'K0', 'K3'], 'v': [4, 5, 6]})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>k</th>\n",
       "      <th>v_x</th>\n",
       "      <th>v_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>K0</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>K0</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    k  v_x  v_y\n",
       "0  K0    1    4\n",
       "1  K0    1    5"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(left=left, right=right, how='inner', on='k')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### join - 组合"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "最后一个数据合并的常用且重要的操作是`join`\n",
    "\n",
    "同样很难找到比官方文档更好的练习，以下案例来源或基于 [👉官方文档](https://pandas.pydata.org/pandas-docs/version/0.20/merging.html#database-style-dataframe-joining-merging) 中的案例修改而来\n",
    "\n",
    "在练习之前应执行每题下方的代码生成数据\n",
    "\n",
    "并应预览不同数据的结构以及每题的图解（如果有）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [],
   "source": [
    "left = pd.DataFrame({'A': ['A0', 'A1', 'A2'],\n",
    "                     'B': ['B0', 'B1', 'B2']},\n",
    "                     index=['K0', 'K1', 'K2'])\n",
    "\n",
    "\n",
    "right = pd.DataFrame({'C': ['C0', 'C2', 'C3'],\n",
    "                      'D': ['D0', 'D2', 'D3']},\n",
    "                      index=['K0', 'K2', 'K3'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 25 -  <font color ='#27BE49'>join</font>｜左对齐\n",
    "\n",
    "合并 left 和 right，并按照 left 的索引进行对齐"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_join.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>K0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A   B    C    D\n",
       "K0  A0  B0   C0   D0\n",
       "K1  A1  B1  NaN  NaN\n",
       "K2  A2  B2   C2   D2"
      ]
     },
     "execution_count": 121,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "left.join(right)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 26 - <font color ='#27BE49'>join</font>｜左对齐（外连接）\n",
    "\n",
    "按下图所示进行连接\n",
    "\n",
    "思考：merge 做法\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_join_outer.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>K0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      A    B    C    D\n",
       "K0   A0   B0   C0   D0\n",
       "K1   A1   B1  NaN  NaN\n",
       "K2   A2   B2   C2   D2\n",
       "K3  NaN  NaN   C3   D3"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "left.join(right, how='outer')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 27 - <font color ='#27BE49'>join</font>｜左对齐（内连接）\n",
    "\n",
    "按下图所示进行连接\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_join_inner.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>K0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "      <td>D2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A   B   C   D\n",
       "K0  A0  B0  C0  D0\n",
       "K2  A2  B2  C2  D2"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "left.join(right, how='inner')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 28 - <font color ='#27BE49'>join</font>｜按索引\n",
    "\n",
    "重新产生数据并按下图所示进行连接（根据 `key`）\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_join_key_columns.png)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [],
   "source": [
    "left = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],\n",
    "                     'B': ['B0', 'B1', 'B2', 'B3'],\n",
    "                     'key': ['K0', 'K1', 'K0', 'K1']})\n",
    "\n",
    "\n",
    "right = pd.DataFrame({'C': ['C0', 'C1'],\n",
    "                      'D': ['D0', 'D1']},\n",
    "                      index=['K0', 'K1'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>key</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>K0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>K0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>K1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>K1</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B key   C   D\n",
       "0  A0  B0  K0  C0  D0\n",
       "2  A2  B2  K0  C0  D0\n",
       "1  A1  B1  K1  C1  D1\n",
       "3  A3  B3  K1  C1  D1"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#pd.merge(left=left, right=right, how='inner', left_on='key', right_on=right.index) \n",
    "# 或\n",
    "left.join(right,how='inner', on='key')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 29 - <font color ='#27BE49'>join</font>｜按索引（多个）\n",
    "\n",
    "重新产生数据并按下图所示进行连接（根据 `key1` 和 `key2`）\n",
    "\n",
    "![](https://pandas.pydata.org/pandas-docs/version/0.20/_images/merging_join_multikeys.png)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {},
   "outputs": [],
   "source": [
    "left = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],\n",
    "                     'B': ['B0', 'B1', 'B2', 'B3'],\n",
    "                     'key1': ['K0', 'K0', 'K1', 'K2'],\n",
    "                     'key2': ['K0', 'K1', 'K0', 'K1']})\n",
    "\n",
    "\n",
    "index = pd.MultiIndex.from_tuples([('K0', 'K0'), ('K1', 'K0'),\n",
    "                                  ('K2', 'K0'), ('K2', 'K1')])\n",
    "\n",
    "\n",
    "right = pd.DataFrame({'C': ['C0', 'C1', 'C2', 'C3'],\n",
    "                   'D': ['D0', 'D1', 'D2', 'D3']},\n",
    "                  index=index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>key1</th>\n",
       "      <th>key2</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A0</td>\n",
       "      <td>B0</td>\n",
       "      <td>K0</td>\n",
       "      <td>K0</td>\n",
       "      <td>C0</td>\n",
       "      <td>D0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>K0</td>\n",
       "      <td>K1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>K1</td>\n",
       "      <td>K0</td>\n",
       "      <td>C1</td>\n",
       "      <td>D1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "      <td>K2</td>\n",
       "      <td>K1</td>\n",
       "      <td>C3</td>\n",
       "      <td>D3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B key1 key2    C    D\n",
       "0  A0  B0   K0   K0   C0   D0\n",
       "1  A1  B1   K0   K1  NaN  NaN\n",
       "2  A2  B2   K1   K0   C1   D1\n",
       "3  A3  B3   K2   K1   C3   D3"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# left.join(right,how='left', on=['key1', 'key2'])\n",
    "# 或\n",
    "pd.merge(left=left, right=right, how='left', left_on=['key1', 'key2'], right_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "e4d85d63baa40a9854e1e91e14fde8d7f9b9a564a40f3bc91b58b47abf2bd79f"
  },
  "kernelspec": {
   "display_name": "Python 3.9.6 64-bit",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "384px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
